//
//  AddSubscriptionViewController.m
//  EMMApp
//
//  Created by Mac on 16/10/26.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "AddSubscriptionViewController.h"
#import "EMMTouristsViewController.h"

#import "NewCustomersCell.h"            //列表cell

#import "AddSubscriptionCell.h"

#import "HousingViewController.h"       //房源选择

#import "GetConsultantListApi.h"        //查询经纪人列表接口Api

#import "AddSubscribeApi.h"             //保存Api

#import "EditSubscribeApi.h"            //修改Api

#import "GetRoomListApi.h"              //查询意向房源

#import "GetRecommendCustomerListHanderApi.h"   //选择推荐人Api

#import "GetDictionaryListApi.h"   //查询字典列表接口

#import "GetDictionaryListByProjectIdApi.h"

#import "NSString+Base64.h"
#import "NSData+Base64.h"
#import "QBImagePickerController.h"
#import "VGReturnPartPicViewCell.h"
#import "EMMImageView.h"
#import "MHPhotoBrowserController.h"
/** ViewController
 *
 *  ViewController导入.h文件
 */
#import "CalculatePriceViewController.h"
#import "EMMPhotoViewController.h"

#import "SubscriptionViewController.h"      //认购列表

@interface AddSubscriptionViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIScrollViewDelegate,UITextViewDelegate,QBImagePickerControllerDelegate,UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>

//显示列表
@property (nonatomic, strong) UITableView *addSubscriptionTableView;

//二级列表是否展开状态
@property (nonatomic, strong) NSMutableArray *selectedArr;

//tableView分区数组
@property (nonatomic, strong) NSMutableArray *titleDataArray;

//分区下对于的标题字典
@property (nonatomic, strong) NSMutableDictionary *titleDict;

//第0分区---
@property (nonatomic, strong) NSMutableArray *section0DataArr;

//第1分区下的数组
@property (nonatomic, strong) NSMutableArray *section1DataArr;

//第1分区 第一行 row = 7 数组
@property (nonatomic, assign) NSInteger rowHitgKH7;

//第2分区---
@property (nonatomic, strong) NSMutableArray *section2DataArr;

//第2分区 第一行 row = 0
@property (nonatomic, assign) NSInteger rowHitgZH0;

//第2分区 第一行 row = 3
@property (nonatomic, assign) NSInteger rowHitgZH3;

//第3分区---
@property (nonatomic, strong) NSMutableArray *section3DataArr;

//第3分区 第一行 row = 2
@property (nonatomic, assign) NSInteger rowRCJH2;

//第4分区---
@property (nonatomic, strong) NSMutableArray *section4DataArr;

//第5分区---
@property (nonatomic, strong) NSMutableArray *section5DataArr;

//房源
@property (nonatomic, strong) RoomList *roomList;

//客户信息
@property (nonatomic, strong) GetCustomerDetail *getCustomerDetail;

//客户证件号Id
@property (nonatomic, strong) NSString *documentTypeId;

//新增参数字段
@property (nonatomic, strong) NSString *roomName;   //房源

//paymentMethodId 付款方式Id
@property (nonatomic, strong) NSString *paymentMethodId;

//paymentMethodId 成交类别Id
@property (nonatomic, strong) NSString *dealCategoryId;

//推荐成交人
@property (nonatomic, strong) NSMutableArray *recommendCustomerList;

//推荐成交人
@property (nonatomic, strong) NSMutableArray *recommendCustomerNameList;

//推荐人id
@property (nonatomic, strong) NSString *referenceNameId;

@property (nonatomic, strong) NSMutableArray *jingjirenArr;

@property (nonatomic, strong) NSMutableArray *zyData;                               //经纪人数组

@property (nonatomic, strong) NSMutableArray *zyDataArr;                            //经纪人数组

@property (nonatomic, strong) NSMutableArray *zyDataArrId;                          //经纪人数组Id

@property (nonatomic, strong) NSString *jlDiscountAmount;//本地记录折扣金额

@property (nonatomic, strong) NSString *jlDijiaAmount;//本地记录低价

@property (nonatomic, strong) NSString *jlDiscountRate;//本地记录折扣比例

//是否折扣审批：0 否；1 是
@property (nonatomic, strong) UILabel *xianshibd;

@property (nonatomic, strong) NSMutableArray *jtcyDataArr;//家庭成员数组

@property (nonatomic, strong) NSMutableDictionary *jtcyDict;//家庭成员字典

/**
 12、证件类型
 */
@property (nonatomic, strong) NSMutableArray *zjlxList;

//邮寄地址textview
@property (nonatomic, strong) UITextView *mailPostTV;

//邮寄地址textview高度
@property (nonatomic, assign) CGFloat mailPostTVHeight;

//备注textview
@property (nonatomic, strong) UITextView *remarkTV;

//备注textview高度
@property (nonatomic, assign) CGFloat remarkTVHeight;

//第6分区---
@property (nonatomic, strong) NSMutableArray *section6DataArr;

//上传图片数组
@property (nonatomic, strong) NSMutableArray *imageList;

/**
 选择图片数组
 */
@property(nonatomic, strong) NSMutableArray* picArray;

/**
 选择图片数组
 */
@property(nonatomic, strong) NSMutableArray* picArray1;

/**
 选择图片数组
 */
@property(nonatomic, strong) NSMutableArray* picArraySele;

@property (nonatomic, assign) BOOL isHaveDian;
@end

@implementation AddSubscriptionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _selectedArr = [[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6", nil];

    _titleDict = [[NSMutableDictionary alloc] init];
    
    _recommendCustomerList = [[NSMutableArray alloc] init];
    
    _recommendCustomerNameList = [[NSMutableArray alloc] init];
    
    _jingjirenArr = [[NSMutableArray alloc] init];
    
    _zyData = [[NSMutableArray alloc] init];
    
    _zyDataArr = [[NSMutableArray alloc] init];
    
    _jtcyDataArr = [[NSMutableArray alloc] init];
    
    _jtcyDict = [[NSMutableDictionary alloc] init];
    
    _imageList = [[NSMutableArray alloc] init];
    
    _picArray = [[NSMutableArray alloc] init];
    NSMutableDictionary *dictIm = [[NSMutableDictionary alloc] init];
    [dictIm setObject:@"image" forKey:@"image"];
    [dictIm setObject:@"type" forKey:@"type"];
    [_picArray addObject:dictIm];
    
    _picArray1 = [[NSMutableArray alloc] init];
    
    _picArraySele = [[NSMutableArray alloc] init];
    //12、证件类型
    _zjlxList = [[NSMutableArray alloc] init];
    [self postGetDictionaryListByProjectIdApi];
    [self postGetRecommendCustomerListHanderApi];
    [self postGetConsultantListApi];
//    [self creatNavigationController];

    [self initWithShowUI];
    [self initDataTitleList];
    
    _addSubscriptionTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH,EMM_HEIGHT-65-SafeAreaTopHeight) style:UITableViewStyleGrouped];
    _addSubscriptionTableView.delegate = self;
    _addSubscriptionTableView.dataSource = self;
    _addSubscriptionTableView.showsVerticalScrollIndicator = NO;
    _addSubscriptionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_addSubscriptionTableView];
    
    if ([_isSFNew isEqualToString:@"0"]) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
        NSDate * date = [NSDate date];//当前时间
        _getSubscribeDetail.subscribeDate = [dateFormatter stringFromDate:date];
    }else {
        _getSubscribeDetail.addDiscountRate = [NSString getMoney2:[_getSubscribeDetail.addDiscountRate floatValue]];
    }
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0, 0, 54 ,44)];
    [backBtn addTarget:self
                action:@selector(NewbackToPreviousPage:)
      forControlEvents:UIControlEventTouchUpInside];
    [backBtn setBackgroundColor:[UIColor clearColor]];
    [backBtn setImage:[UIImage imageNamed:@"ico_back"] forState:UIControlStateNormal];
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    if (EMM_WIDTH <= 320) {
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }else if (EMM_WIDTH > 375){
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }else{
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    
    NSString *resetPrice = [NSString stringWithFormat:@"%.2f", [self.getSubscribeDetail.discountTotalPrice floatValue] * 10000];
    self.getSubscribeDetail.discountTotalPrice = resetPrice;
    NSString *resetAfterPrice = [NSString stringWithFormat:@"%.2f", [self.getSubscribeDetail.discountAfterAmount floatValue] * 10000];
    self.getSubscribeDetail.discountAfterAmount = resetAfterPrice;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
}

- (void)NewbackToPreviousPage:(id) send {
    if ([_isTransaction isEqualToString:@"1"]) {
        [self creatNSNotificationCenter];
        for (UIViewController *controller in self.navigationController.viewControllers) {
            if ([controller isKindOfClass:[SubscriptionViewController class]]) {
                SubscriptionViewController *svc =(SubscriptionViewController *)controller;
                [self.navigationController popToViewController:svc animated:YES];
            }
        }
    }else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}


#pragma mark - 完善客户信息-认购返回的回调通知
- (void)creatNSNotificationCenter {
    NSDictionary *dict = [NSDictionary dictionaryWithObject:@"A" forKey:@"intentionLevel"];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"SubscriptionVCIntentionLevel" object:nil userInfo:dict];
}


#pragma  mark - 证件号类型
- (void)postGetDictionaryListByProjectIdApi {
    
    GetDictionaryListByProjectIdApi *api = [[GetDictionaryListByProjectIdApi alloc] initWithBusNum:@"01"];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetDictionaryListByProjectIdApi *result = (GetDictionaryListByProjectIdApi *)request;
        if (result.isSuccess) {
            GetDictionaryListByProjectId *get = result.resultData;
            //12、证件类型
            _zjlxList = [get.typeMap objectForKey:@"documentType"];
            if ([_isSFNew isEqualToString:@"0"]) {
                [self postGetCustomerDetailApi];
            }
        } else {
            [self showToast:result.resultData.errorMsg];
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
        [self creatNavigationController];
        [self initDataTitleList];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
        
    }];
}

#pragma mark - 推荐成交人
- (void)postGetRecommendCustomerListHanderApi {
    [_recommendCustomerList removeAllObjects];
    [_recommendCustomerNameList removeAllObjects];
    GetRecommendCustomerListHanderApi *api = [[GetRecommendCustomerListHanderApi alloc] initWithResourcesCode:@"menu_0006_0001"];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetRecommendCustomerListHanderApi *result = (GetRecommendCustomerListHanderApi *)request;
        if (result.isSuccess) {
            GetRecommendCustomerListHander *get = result.resultData;
            for (RecommendCustomerList *list in get.recommendCustomerList) {
                [_recommendCustomerNameList addObject:list.customerName];
                [_recommendCustomerList addObject:list];
            }
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];

    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];

    }];
}

#pragma  mark - 经纪人
- (void)postGetConsultantListApi {
    [_zyDataArr removeAllObjects];
    [_zyData removeAllObjects];
    GetConsultantListApi *api = [[GetConsultantListApi alloc] initWithResourcesCode:nil searchType:nil];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetConsultantListApi *result = (GetConsultantListApi *)request;
        if (result.isSuccess) {
            GetConsultantList *get = result.resultData;

            for (ConsultantList *list in get.consultantList) {
                [_zyDataArr addObject:list.consultantUserName];
                [_zyData addObject:list];
            }
        } else {
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
//        [self hideHud];

        [self creatNavigationController];
        [self initDataTitleList];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
//        [self hideHud];

    }];
}

#pragma mark - 导航
- (void)creatNavigationController {
    [self updateNavBar];
    if ([_isSFNew isEqualToString:@"0"]) {
        self.navigationItem.title = @"新增认购";
        [_jingjirenArr removeAllObjects];
//        [self postGetCustomerDetailApi];
        _getSubscribeDetail.dealCategory = @"单独成交";
        _dealCategoryId = @"2";
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
        NSString *userName = [userdf objectForKey:@"userName"];
        NSString *userId = [userdf objectForKey:@"userNameId"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        [dict setObject:userId forKey:@"relationAgentId"];
        [dict setObject:userName forKey:@"relationAgentName"];
        [dict setObject:@"100" forKey:@"proportionCommission"];
        [_jingjirenArr addObject:dict];
    }else {
        [self creatBianJiShowUI];
       
        self.navigationItem.title = @"编辑认购";
    }
}

#pragma mark - 编辑
- (void)creatBianJiShowUI {
    [_jingjirenArr removeAllObjects];
    [_jtcyDataArr removeAllObjects];
    [_picArray removeAllObjects];
    if ([_getSubscribeDetail.floorType isEqualToString:@"0"]) {
        _rowHitgZH0 = 50;
        _rowHitgZH3 = 0;
    }else {
        _rowHitgZH0 = 0;
        _rowHitgZH3 = 0;
    }
    
    NSArray *dealCategoryArr = [NSArray arrayWithObjects:
                    @"推荐成交",@"单独成交",@"共同成交", nil];
    for (int i = 0; i < dealCategoryArr.count; i++) {
        NSString *str = [dealCategoryArr objectAtIndex:i];
        if ([_getSubscribeDetail.dealCategory isEqualToString:str]) {
            _dealCategoryId = [NSString stringWithFormat:@"%d",i+1];
        }
    }
   
    
    NSArray *paymentMethodArr = [NSArray arrayWithObjects:
                                 @"一次性付款",@"分期付款",@"商业按揭",
                                 @"公积金按揭 ", @"组合贷款", nil];
    for (int i = 0; i < paymentMethodArr.count; i++) {
        NSString *str = [paymentMethodArr objectAtIndex:i];
        if ([_getSubscribeDetail.paymentMethod isEqualToString:str]) {
            _paymentMethodId = [NSString stringWithFormat:@"%d",i+1];
        }
    }
    
    for (int i = 0; i < _getSubscribeDetail.dealCategoryList.count; i++) {
        DealCategoryList *list = [_getSubscribeDetail.dealCategoryList objectAtIndex:i];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        if ([NSString isStringEmpty2:list.relationAgentId] == NO) {
            [dict setObject:list.relationAgentId forKey:@"relationAgentId"];
        }
        
        if ([NSString isStringEmpty2:list.relationAgentName] == NO) {
            [dict setObject:list.relationAgentName forKey:@"relationAgentName"];
        }
        
        if ([NSString isStringEmpty2:list.proportionCommission] == NO) {
            [dict setObject:list.proportionCommission forKey:@"proportionCommission"];
        }
        [_jingjirenArr addObject:dict];
    }
    
    NSMutableArray *jtDataArr = [[NSMutableArray alloc] init];
    for (int i = 0; i < _getSubscribeDetail.customerFamilyList.count; i++) {
        CustomerFamilyList *list = [_getSubscribeDetail.customerFamilyList objectAtIndex:i];
        [jtDataArr addObject:list];
    }
    if (_zjlxList.count > 0) {
        for (int i = 0; i < jtDataArr.count; i++) {
            CustomerFamilyList *list = [jtDataArr objectAtIndex:i];
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            [dict setObject:list.memberName forKey:@"memberName"];
            
            NSString *documentType = nil;
            for (int i = 0; i < _zjlxList.count; i++) {
                NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
                if ([list.documentType isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                    documentType = [dict objectForKey:@"dictionaryId"];
                }else {
                    documentType = @"";
                }
            }
            [dict setObject:documentType forKey:@"documentType"];
            [dict setObject:list.documentNumber forKey:@"documentNumber"];
            [_jtcyDataArr addObject:dict];
        }
    }
    
    UITextView *mailPostTextView = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
    mailPostTextView.font = [UIFont systemFontOfSize:15];
    mailPostTextView.text = _getSubscribeDetail.mailPost;
    _mailPostTVHeight = [self heightForString:mailPostTextView andWidth:EMM_WIDTH - 100];
    
    for (ImageList *list in _getSubscribeDetail.imageList) {
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        if ([NSString isStringEmpty2:list.smallUrl] == NO) {
            [dict setObject:list.smallUrl forKey:@"image"];
        }
        [dict setObject:@"2" forKey:@"type"];
        [_picArray addObject:dict];
    }
    
    NSMutableDictionary *dictIm = [[NSMutableDictionary alloc] init];
    [dictIm setObject:@"image" forKey:@"image"];
    [dictIm setObject:@"type" forKey:@"type"];
    [_picArray addObject:dictIm];
}
#pragma mark - 创建每一个分区数组
- (void)initDataTitleList {
    _titleDataArray = [[NSMutableArray alloc] initWithObjects:
                       @"房源信息", @"客户信息",
                       @"2",@"3",@"4",@"5",@"附件", nil];
    
    //第0分区
    _section0DataArr = [[NSMutableArray alloc] initWithObjects:@"认购编号",@"认购房源",@"计价面积",@"折前单价",@"折前总价", nil];
    [_titleDict setObject:_section0DataArr forKey:@"0"];
    
    //第1分区
    _section1DataArr = [[NSMutableArray alloc] initWithObjects:
                   @"新增客户信息",@"客户姓名",@"证件类型",@"证件号码",
                   @"手机号码",@"邮寄地址",@"邮  编", @"", nil];
    _rowHitgKH7 = 0;
    [_titleDict setObject:_section1DataArr forKey:@"1"];
    
    
    //第2分区
    _section2DataArr = [[NSMutableArray alloc] initWithObjects:@"折后总价",@"折扣金额",@"折扣比例", @"优惠原因", @"折扣说明", nil];
    if ([_isSFNew isEqualToString:@"0"]) {
        _rowHitgZH0 = 50;
        _rowHitgZH3 = 0;
    }
    [_titleDict setObject:_section2DataArr forKey:@"2"];
    
    //第3分区
    _section3DataArr = [[NSMutableArray alloc] initWithObjects:@"签约单价", @"房款合同金额",@"已收认筹金",@"认购金",@"付款方式",@"成交类别", nil];
    if ([NSString isStringEmpty2:_getSubscribeDetail.realAmount] == NO) {
        _rowRCJH2 = 50;
    }else {
        _rowRCJH2 = 0;
    }
    [_titleDict setObject:_section3DataArr forKey:@"3"];
    
    //第4分区
    _section4DataArr = [[NSMutableArray alloc] initWithObjects:@"经纪人",@"",nil];
    [_titleDict setObject:_section4DataArr forKey:@"4"];
    //第5分区
    if ([_dealCategoryId isEqualToString:@"1"]) {
        _section5DataArr = [[NSMutableArray alloc] initWithObjects:@"推荐人",@"认购日期",@"认购转合同到期日期", @"备注",nil];
        [_titleDict setObject:_section5DataArr forKey:@"5"];
    }else {
        _section5DataArr = [[NSMutableArray alloc] initWithObjects:@"认购日期",@"认购转合同到期日期", @"备注",nil];
        [_titleDict setObject:_section5DataArr forKey:@"5"];
    }
    //计算备注textView的高度
    UITextView *remarkTextView = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
    remarkTextView.font = [UIFont systemFontOfSize:15];
    remarkTextView.text = _getSubscribeDetail.remark;
    _remarkTVHeight = [self heightForString:remarkTextView andWidth:EMM_WIDTH - 100];
    
    _section6DataArr = [[NSMutableArray alloc]initWithObjects:@"",nil];
    [_titleDict setObject:_section6DataArr forKey:@"6"];
}

#pragma mark - 查询客户详情api
- (void)postGetCustomerDetailApi {

    GetCustomerDetailApi *api = [[GetCustomerDetailApi alloc] initWithCustomerId:self.customerId];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetCustomerDetailApi *result = (GetCustomerDetailApi *)request;
        if (result.isSuccess) {
            GetCustomerDetail *get = result.resultData;
            _getSubscribeDetail.customerName = get.customerName;
            _getSubscribeDetail.documentType= get.peDocumentType;
            _getSubscribeDetail.documentNumber = get.peDocumentNumber;
            _getSubscribeDetail.mobile = get.customerPhone;
            _getSubscribeDetail.mailPost = get.peContactAddress;
            _getSubscribeDetail.postcode = get.pePostcode;
            
            //计算textView的高度（邮寄地址）
            UITextView *mailPostTextView = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
            mailPostTextView.font = [UIFont systemFontOfSize:15];
            mailPostTextView.text = _getSubscribeDetail.mailPost;
            _mailPostTVHeight = [self heightForString:mailPostTextView andWidth:EMM_WIDTH - 100];
            
            for (int i = 0; i < _zjlxList.count; i++) {
                NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
                if ([_getSubscribeDetail.documentType isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                    _documentTypeId = [dict objectForKey:@"dictionaryId"];
                }
            }
           
        } else {
//            [self showToast:result.resultData.errorMsg];
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [_addSubscriptionTableView reloadData];
//        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
//        [self hideHud];
    }];
}

#pragma mark - 新增房源详情页面添加认购信息
- (void)openClientPage {
    
//    _getSubscribeDetail.customerName = get.customerName;
//    _getSubscribeDetail.documentType= get.peDocumentType;
//    _getSubscribeDetail.documentNumber = get.peDocumentNumber;
//    _getSubscribeDetail.mobile = get.customerPhone;
//    _getSubscribeDetail.mailPost = get.peContactAddress;
//    _getSubscribeDetail.postcode = get.pePostcode;
    // 跳转客户选择页面
        EMMTouristsViewController *evc = [[EMMTouristsViewController alloc] init];
        evc.hidesBottomBarWhenPushed = YES;
        evc.tourSring = @"4";
        evc.titleString = @"选择客户";
        evc.suanjiaTpye = @"1";
        [self.navigationController pushViewController:evc animated:YES];
        [evc setTouristsBlock:^(NSMutableArray *dataArr) {
            CustomerList *userModel = dataArr.firstObject;
//            self.getSubscribeDetail.customerName = userModel.customerName;
//            self.getSubscribeDetail.mobile = userModel.mobile;
            self.customerId = userModel.customerId;
            [self postGetCustomerDetailApi];
        }];

}


#pragma mark----tableViewDelegate
//返回几个表头
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return _titleDataArray.count;
}

#pragma mark---- 每一个表头下返回几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *string = [NSString stringWithFormat:@"%ld",section];
  
    if ([_selectedArr containsObject:string]) {
        NSArray *array1 = _titleDict[string];
        return array1.count;
    }
    return 0;
}

#pragma mark---- 设置表头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  
    if (section == 2 || section == 3 || section == 4 || section == 5) {
        return 0.1f;
    }
    return 50;
}

#pragma mark---- Section Footer的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 0) {
        return 5.0f;
    }
    return 0.1f;
}

#pragma mark---- 加载cell尾视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    if (section == 0) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 5)];
        view.backgroundColor = [UIColor colorFromHexCode:@"#E4E4E4"];
        return view;
    }else {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 0.1f)];
        view.backgroundColor = [UIColor whiteColor];
        return view;
    }
    return nil;
}

#pragma mark---- 头视图、设置view，将替代titleForHeaderInSection方法
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
    view.backgroundColor = [UIColor whiteColor];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, tableView.frame.size.width-20, 20)];
    titleLabel.text = [_titleDataArray objectAtIndex:section];
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
    [view addSubview:titleLabel];
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
    lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, EMM_WIDTH, 50);
    button.tag = 100+section;
    [button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    view.backgroundColor = [UIColor colorFromHexCode:@"#fff5e9"];
    UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 2, 30)];
    sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    [view addSubview:sLabel6];
  
    UIImageView *upImageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-30, 20, 20, 10)];
    [view addSubview:upImageView];
    
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if ([_selectedArr containsObject:string]) {
        upImageView.image = [UIImage imageNamed:@"sanjt_down"];
    }else {
        upImageView.image = [UIImage imageNamed:@"sanjt_up"];
    }

//    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if (section == 2 || section == 3 || section == 4 || section == 5) {
        return nil;
    }
    return view;
}

#pragma mark - cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];
    if ([indexStr isEqualToString:@"0"]) {
        if (indexPath.row == 1) {
            NSInteger h = [IDTools textHeightFromTextString:_getSubscribeDetail.subscribeHouses width:[UIScreen mainScreen].bounds.size.width-115 fontSize:15]+30;
            if (h <= 50) {
                h = 50;
            }
            return h;
        }
        return 50;
    }else if ([indexStr isEqualToString:@"1"]) {
        if (indexPath.row == 5) {//邮寄地址
            if (_mailPostTVHeight == 0) {
                _mailPostTVHeight = 34;
            }
            return _mailPostTVHeight + 16;
        }
         if (indexPath.row == 7) {
             return _jtcyDataArr.count * 200;
         }
     }else if ([indexStr isEqualToString:@"2"]) {
         if (indexPath.row == 0) {
             return _rowHitgZH0;
         }else if (indexPath.row == 3) {
             return _rowHitgZH3;
         }else {
             return 50;
         }
     }else if ([indexStr isEqualToString:@"3"]) {
         if (indexPath.row == 2) {
             return _rowRCJH2;
         }else {
             return 50;
         }
     }else if([indexStr isEqualToString:@"4"]) {
         if (indexPath.row == 1) {
             return _jingjirenArr.count * 150;
         }else {
             return 50;
         }
     }else if ([indexStr isEqualToString:@"5"]) {
         
         if ([_dealCategoryId isEqualToString:@"1"]) {
             if (indexPath.row == 3) {//备注
                 if (_remarkTVHeight == 0) {
                     _remarkTVHeight = 34;
                 }
                 return _remarkTVHeight + 16;
             }
         }else{
             if (indexPath.row == 1) {//备注
                 if (_remarkTVHeight == 0) {
                     _remarkTVHeight = 34;
                 }
                 return _remarkTVHeight + 16;
             }
         }
     }else if ([indexStr isEqualToString:@"6"]) {
         if (indexPath.row == 0) {
             NSInteger colx = _picArray.count%3;
             NSInteger coly = _picArray.count/3;
             
             if (colx != 0) {
                 coly = coly + 1;
             }
             
             CGFloat appMargin=(EMM_WIDTH-3*100)/(3+1);
             
             return (100+appMargin)*coly;
         }
     }
    return 50;
}

#pragma mark---- 加载cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
#pragma mark- 总体显示的tabelView
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];
    static NSString *CellIdentifier = @"AddSubscriptionCellId";
    AddSubscriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"AddSubscriptionCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.subTiltleTF.delegate = self;
    cell.subOneTF.delegate = self;
    cell.subTiltleTF.tag = indexPath.row + 100;
    cell.subOneTF.tag = indexPath.row + 100;
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
    lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    [cell addSubview:lineImage];
    
#pragma mark -  cell分区0 indexPath.section = 0
    if ([indexStr isEqualToString:@"0"]) {
        
        cell.titleLabel.text = [_section0DataArr objectAtIndex:indexPath.row];
        if (indexPath.row == 0) {
            //认购编号
            cell.subOneTF.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.subscribeCode] == NO) {
                cell.subOneTF.text = _getSubscribeDetail.subscribeCode;
            }else {
                cell.subOneTF.placeholder = @"请输入认购编号";
            }
            [cell.subOneTF addTarget:self action:@selector(superOneTilteTextFieldClick:) forControlEvents:UIControlEventEditingChanged];
        }else if (indexPath.row == 1) {
            //房源选择
            NSInteger h = [IDTools textHeightFromTextString:_getSubscribeDetail.subscribeHouses width:[UIScreen mainScreen].bounds.size.width-115 fontSize:15]+30;
            if (h > 50) {
                lineImage.frame = CGRectMake(10, h - 0.5, EMM_WIDTH-20, 0.5);
            }
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.subscribeHouses] == NO) {
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#000000"];
                cell.subTitleLabel.text = _getSubscribeDetail.subscribeHouses;
            }else {
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                cell.subTitleLabel.text = @"请选择房源";
            }
            // 从房源详情页面进来时，隐藏箭头
            cell.btn_qiaoJImageV.hidden = self.HouseingDetailTo;
            
            
            cell.seleBtn.hidden = NO;
            [cell.seleBtn addTarget:self action:@selector(roomFYBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }else if (indexPath.row == 2) {
            //计价面积
            if ([NSString isStringEmpty2:_getSubscribeDetail.calculateArea] == NO) {
                cell.subtitleOneLable.text = [NSString stringWithFormat:@"%@m²",_getSubscribeDetail.calculateArea];
            }else {
                cell.subtitleOneLable.text = @"m²";
            }
        }else if (indexPath.row == 3) {
            //折前单价
            if ([NSString isStringEmpty2:_getSubscribeDetail.discountPrice] == NO) {
                cell.subtitleOneLable.text = [NSString stringWithFormat:@"%.2f元",[_getSubscribeDetail.discountPrice floatValue]];
            }else {
                cell.subtitleOneLable.text = @"元";
            }
        }else if (indexPath.row == 4) {
            //折前总价
            cell.subTiltleTF.hidden = YES;
            cell.danweiLabel.hidden = NO;
            cell.danweiLabel.text = @"元";
            cell.subTitleLabel.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.discountTotalPrice] == NO) {
                cell.subtitleOneLable.text = [NSString stringWithFormat:@"%.2f元",[_getSubscribeDetail.discountTotalPrice floatValue]];
            }else {
                cell.subtitleOneLable.text = @"元";
            }
        }
    }else if([indexStr isEqualToString:@"1"]) {
#pragma mark -  cell分区1 indexPath.section = 1
       
        cell.subTiltleTF.delegate = self;
        cell.titleLabel.text = [_section1DataArr objectAtIndex:indexPath.row];
//        cell.subTiltleTF.tintColor = [UIColor orangeColor];
        [cell.subOneTF addTarget:self action:@selector(section1TextFieldClick:) forControlEvents:UIControlEventEditingChanged];
        cell.subOneTF.keyboardType = UIKeyboardTypeDefault;
        if (indexPath.row == 0) {
            //新增客户信息
            cell.subTiltleTF.hidden = YES;
            cell.subTitleLabel.hidden = YES;
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-40, 10, 30, 30)];
            imageView.image = [UIImage imageNamed:@"rc_add"];
            [cell addSubview:imageView];
            cell.seleBtn.hidden = NO;
            [cell.seleBtn addTarget:self action:@selector(newKHCYBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }else if (indexPath.row == 1) {
            /**
             *  功能描述：
             *  1.修改姓名可以更改
             *  创建时间：16/10/26
             *
             *  更新时间：2017/02/17 下午
             *  更新人： wangguiping
             */
            //客户姓名
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
//            cell.subTiltleTF.hidden = YES;
//            cell.subTitleLabel.hidden = NO;
//            if ([NSString isStringEmpty2:_getSubscribeDetail.customerName] == NO) {
//                cell.subtitleOneLable.text = _getSubscribeDetail.customerName;
//            }
            cell.subOneTF.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.customerName] == NO) {
                cell.subOneTF.text = _getSubscribeDetail.customerName;
            }else {
                cell.subOneTF.placeholder = @"请选择客户";
            }
            cell.subOneTF.tag = 1;

            if(self.HouseingDetailTo) {
                cell.subOneTF.userInteractionEnabled = NO;
                cell.seleBtn.hidden = NO;
                [cell.seleBtn addTarget:self action:@selector(openClientPage) forControlEvents:UIControlEventTouchUpInside];
            }

        }else if (indexPath.row == 2) {
            //证件类型
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.subTiltleTF.hidden = YES;
            cell.subTitleLabel.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.documentType] == NO) {
                cell.subTitleLabel.text = _getSubscribeDetail.documentType;
            }else {
                cell.subTitleLabel.text = @"请选择证件类型";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            }
            cell.btn_qiaoJImageV.hidden = NO;
            cell.seleBtn.hidden = NO;
            [cell.seleBtn addTarget:self action:@selector(documentTypeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }else if (indexPath.row == 3) {
            //证件号
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.subOneTF.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.documentNumber] == NO) {
                cell.subOneTF.text = _getSubscribeDetail.documentNumber;
            }else {
                cell.subOneTF.placeholder = @"请输入证件号码";
            }
            cell.subOneTF.tag = 3;
        }else if (indexPath.row == 4) {
            //手机号
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            if ([NSString isStringEmpty2:_getSubscribeDetail.mobile] == NO) {
                cell.subtitleOneLable.text = _getSubscribeDetail.mobile;
            }else {
                cell.subtitleOneLable.text = @"";
            }
        }else if (indexPath.row == 5) {
          //邮寄地址
            cell.subOneTF.hidden = YES;
            _mailPostTV = [[UITextView alloc] initWithFrame:CGRectMake(60 + 30, 5, EMM_WIDTH-100, _mailPostTVHeight + 6)];
            _mailPostTV.delegate = self;
            _mailPostTV.returnKeyType =UIReturnKeyDone;
            _mailPostTV.textAlignment = NSTextAlignmentRight;
            [cell addSubview:_mailPostTV];
            _mailPostTV.font = [UIFont systemFontOfSize:15];
            if ([NSString isStringEmpty2:_getSubscribeDetail.mailPost] == NO) {
                _mailPostTV.text = _getSubscribeDetail.mailPost;
                _mailPostTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                _mailPostTV.text = @"请输入邮寄地址";
                _mailPostTV.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            }
            lineImage.hidden = YES;
            UIImageView *lineImage1 = [[UIImageView alloc] init];
            lineImage1.frame = CGRectMake(10, _mailPostTVHeight + 16 - 0.5, EMM_WIDTH - 20, 0.5);
            lineImage1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            [cell addSubview:lineImage1];

        }else if (indexPath.row == 6) {
            //邮编
            cell.subOneTF.hidden = NO;
            cell.subOneTF.keyboardType = UIKeyboardTypeNumberPad;
            if ([NSString isStringEmpty2:_getSubscribeDetail.postcode] == NO) {
                cell.subOneTF.text = _getSubscribeDetail.postcode;
            }else {
                cell.subOneTF.placeholder = @"请输入邮编";
            }
            cell.subOneTF.tag = 6;

        }else {
            //加载家庭成员的tableView
            lineImage.hidden = YES;
            cell.subTiltleTF.hidden = YES;
            cell.subTitleLabel.hidden = YES;
#warning 111
            for (int i = 0; i < _jtcyDataArr.count; i++) {
                NSMutableDictionary *dict = [_jtcyDataArr objectAtIndex:i];
                NSString *nameString = [dict objectForKey:@"memberName"];
                NSString *documentType = [dict objectForKey:@"documentType"];
                NSString *documentTypeName = nil;
                NSString *documentNumber = [dict objectForKey:@"documentNumber"];
                
                if ([NSString isStringEmpty2:documentType] == NO) {

//                    for (int i = 0; i < _zjlxList.count; i++) {
//                        RqBusNumList *list = [_zjlxList objectAtIndex:i];
//                        if ([documentType isEqualToString:list.dictionaryId]) {
//                            documentTypeName = list.dictionaryName;
//                        }
//                    }
//                    
                    for (int i = 0; i < _zjlxList.count; i++) {
                        NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
                        if ([documentType isEqualToString:[dict objectForKey:@"dictionaryId"]]) {
                            documentTypeName = [dict objectForKey:@"dictionaryName"];
                        }
                    }
                }
                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i*200, EMM_WIDTH, 200)];
                UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
                v1.backgroundColor = [UIColor colorFromHexCode:@"#FFF5E9"];
                [view addSubview:v1];
                UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 2, 30)];
                sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
                [view addSubview:sLabel6];
                
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(EMM_WIDTH-40, 10, 30, 30);
                [button setImage:[UIImage imageNamed:@"rc_dlet"] forState:UIControlStateNormal];
                button.tag = 100 + i;
                [button addTarget:self action:@selector(dletjtcyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                [view addSubview:button];
                [cell addSubview:view];
                
                UILabel *titllName = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 100, 20)];
                titllName.font = [UIFont systemFontOfSize:15];
                titllName.text = [NSString stringWithFormat:@"家庭成员%d", i+1];
                [view addSubview:titllName];
                
                UILabel *titllName1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 65, 100, 20)];
                titllName1.font = [UIFont systemFontOfSize:15];
                titllName1.text = @"客户姓名";
                titllName1.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];

                [view addSubview:titllName1];
                
                UITextField *nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 60, EMM_WIDTH-120, 30)];
                nameTextField.font = [UIFont systemFontOfSize:15];
                nameTextField.textAlignment = NSTextAlignmentRight;
                nameTextField.delegate = self;
                nameTextField.tag = 100 + i;
                [nameTextField addTarget:self action:@selector(khNameTextFieldClick:) forControlEvents:UIControlEventEditingChanged];
                if ([NSString isStringEmpty2:nameString] == NO) {
                    nameTextField.text = nameString;
                    nameTextField.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                }else {
                    nameTextField.placeholder = @"请输入";
                }
                [view addSubview:nameTextField];
                
                UIImageView *lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 99, EMM_WIDTH-20, 1)];
                lineImage1.backgroundColor = [UIColor colorFromHexCode:@"#e4e4e4"];
                [view addSubview:lineImage1];
                
                UILabel *titllName2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 115, 100, 20)];
                titllName2.font = [UIFont systemFontOfSize:15];
                titllName2.text = @"证件类型";
                titllName2.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];

                [view addSubview:titllName2];
                
                UILabel *tNameLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(110, 115, EMM_WIDTH-135, 20)];
                tNameLabel2.font = [UIFont systemFontOfSize:15];
                tNameLabel2.textAlignment = NSTextAlignmentRight;
                [view addSubview:tNameLabel2];
                
                if ([NSString isStringEmpty2:documentTypeName] == NO) {
                    tNameLabel2.text = documentTypeName;
                    tNameLabel2.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];

                }else {
                    tNameLabel2.text = @"未选择";
                    tNameLabel2.textColor = [UIColor colorFromHexCode:@"#C7C7CD"];
                }
                
                UIImageView *lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 149.5, EMM_WIDTH-20, 0.5)];
                lineImage2.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [view addSubview:lineImage2];
                
                UIImageView *im = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-10-12, 100+(50-16)/2, 12, 16)];
                im.image = [UIImage imageNamed:@"btn_qiaoj"];
                [view addSubview:im];
                
                UIButton *jjrbtn = [UIButton buttonWithType:UIButtonTypeSystem];
                jjrbtn.frame =CGRectMake(0, 115, EMM_WIDTH, 50);
                [jjrbtn addTarget:self action:@selector(zjleiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                jjrbtn.tag = 100 + i;
                [view addSubview:jjrbtn];
                
                UILabel *titllName3 = [[UILabel alloc] initWithFrame:CGRectMake(10, 165, 100, 20)];
                titllName3.font = [UIFont systemFontOfSize:15];
                titllName3.text = @"证件号码";
                titllName3.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];
                [view addSubview:titllName3];
                
                UITextField *zjhmTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 160, EMM_WIDTH-120, 30)];
                zjhmTextField.font = [UIFont systemFontOfSize:15];
                zjhmTextField.textAlignment = NSTextAlignmentRight;
                zjhmTextField.delegate = self;
                zjhmTextField.tag = 100 + i;
                [zjhmTextField addTarget:self action:@selector(zjhmTextFieldFieldClick:) forControlEvents:UIControlEventEditingChanged];

                if ([NSString isStringEmpty2:documentNumber] == NO) {
                    zjhmTextField.text = documentNumber;
                    zjhmTextField.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];

                }else {
                    zjhmTextField.placeholder = @"请输入";
                }
                [view addSubview:zjhmTextField];
                
                UIImageView *lineImage3 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 199, EMM_WIDTH-20, 1)];
                lineImage3.backgroundColor = [UIColor colorFromHexCode:@"#e4e4e4"];
                [view addSubview:lineImage3];
            }
        }
    }else if ([indexStr isEqualToString:@"2"]) {
#pragma mark -  cell分区2 indexPath.section = 2

        cell.titleLabel.text = [_section2DataArr objectAtIndex:indexPath.row];
        [cell.subTiltleTF addTarget:self action:@selector(section2TextFieldClick:) forControlEvents:UIControlEventEditingChanged];
        [cell.subOneTF addTarget:self action:@selector(section2TextFieldClick:) forControlEvents:UIControlEventEditingChanged];

        if (indexPath.row == 0) {
            //折后总价
            if (_rowHitgZH0 == 0) {
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = YES;
                cell.titleLabel.hidden = YES;
            }else {
                cell.subTiltleTF.hidden = NO;
                cell.subtitleOneLable.text = @"元";
                cell.subTiltleTF.keyboardType = UIKeyboardTypeDecimalPad;
                if ([NSString isStringEmpty2:_getSubscribeDetail.discountAfterAmount] == NO) {
                    cell.subTiltleTF.text = [NSString stringWithFormat:@"%.2f",[_getSubscribeDetail.discountAfterAmount floatValue]];
                }else {
                    cell.subTiltleTF.placeholder = @"请输入折后总价";
                }
                if ([NSString isStringEmpty2:_getSubscribeDetail.discountAfterAmount] == NO) {
                    float dis4 = [_getSubscribeDetail.discountRate floatValue];//浮动值
                    float d1 = [_getSubscribeDetail.discountAfterAmount floatValue];//算出的比例值
                    if (d1 < dis4) {
                        _getSubscribeDetail.discountApproval = @"1";
                    }else {
                        _getSubscribeDetail.discountApproval = @"0";
                    }
                }else {
                    _getSubscribeDetail.discountApproval = @"0";
                }
               
            }
            cell.subTiltleTF.tag = 0;
        }else if (indexPath.row == 1) {
            //折扣金额
            cell.subtitleOneLable.text = @"元";
            if ([_getSubscribeDetail.floorType isEqualToString:@"0"]) {
                //不可输入
                cell.subTiltleTF.userInteractionEnabled = NO;
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = NO;
                cell.subTitleLabel.text =  [NSString stringWithFormat:@"%.2f",[_getSubscribeDetail.discountAmount floatValue]];
            }else {
                //可输入
                cell.subTiltleTF.userInteractionEnabled = YES;
                cell.subTiltleTF.hidden = NO;
                cell.subTitleLabel.hidden = YES;
                cell.subTiltleTF.keyboardType = UIKeyboardTypeDecimalPad;
                if ([NSString isStringEmpty2:_getSubscribeDetail.discountAmount] == NO && ![_getSubscribeDetail.discountAmount isEqualToString:@""]) {

                    cell.subTiltleTF.text =  [NSString stringWithFormat:@"%.2f",[_getSubscribeDetail.discountAmount floatValue]];
                }else {
                    cell.subTiltleTF.placeholder = @"请输入折扣金额";
                }
            }
            cell.subTiltleTF.tag = 1;

        }else if (indexPath.row == 2) {
            //折扣比例两者都不能输入
            cell.subTiltleTF.hidden = NO;
            cell.subtitleOneLable.text = @"%";
//            cell.subTitleLabel.text = _getSubscribeDetail.addDiscountRate;
            if ([_getSubscribeDetail.floorType isEqualToString:@"0"]) {
                //不可输入
                cell.subTiltleTF.userInteractionEnabled = NO;
                cell.subTiltleTF.text = _getSubscribeDetail.addDiscountRate;
            }else {
                
                
                if ([NSString isStringEmpty2:_getSubscribeDetail.addDiscountRate] == NO) {
                    //不可输入
                    cell.subTiltleTF.userInteractionEnabled = NO;
                    cell.subTiltleTF.text = _getSubscribeDetail.addDiscountRate;
                    float dis4 = [_getSubscribeDetail.discountRate floatValue] ;//浮动值
                    float d1 = [_getSubscribeDetail.addDiscountRate floatValue];//算出的比例值
                    if (d1 < dis4) {
                        _getSubscribeDetail.discountApproval = @"1";
                    }else {
                        
                        _getSubscribeDetail.discountApproval = @"0";
                    }
                }else {
                    cell.subTiltleTF.keyboardType = UIKeyboardTypeDecimalPad;
                    cell.subTiltleTF.userInteractionEnabled = YES;
                    cell.subTiltleTF.placeholder = @"请输入折扣比例";
                }
            }
            
            cell.subTiltleTF.tag = 2;

        }else if (indexPath.row == 3) {
            //优惠原因选择比例方案是要显示发起审批，低价不需要显示发起审批
            lineImage.hidden = YES;
            
            if (_rowHitgZH3 == 0) {
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = YES;
                cell.titleLabel.hidden = YES;
            }else {
                UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, _rowHitgZH3-0.5, EMM_WIDTH-20, 0.5)];
                lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [cell addSubview:lineImage];
                
                lineImage.frame = CGRectMake(10, 79, EMM_WIDTH-20, 1);
                _xianshibd = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, EMM_WIDTH-40, 40)];
                _xianshibd.font = [UIFont systemFontOfSize:12];
                _xianshibd.numberOfLines = 0;
                NSString *s = @"%";
                
                _xianshibd.text = [NSString stringWithFormat:@"当前折扣%@%@低于比例浮动值%.0f%@，需要发起折扣审批",_getSubscribeDetail.addDiscountRate ,s,[_getSubscribeDetail.discountRate floatValue],s];
                [cell addSubview:_xianshibd];
                if ([NSString isStringEmpty2:_getSubscribeDetail.addDiscountRate] == NO) {
                    float dis4 = [_getSubscribeDetail.discountRate floatValue] ;//浮动值
                    float d1 = [_getSubscribeDetail.addDiscountRate floatValue];//算出的比例值
                    if (d1 < dis4) {
                        _xianshibd.hidden = NO;
                       
                    }else {
                        _xianshibd.hidden = YES;
                    }
                }else {
                    _xianshibd.hidden = YES;
                }
                
//                cell.subOneTF.hidden = NO;
//                if ([NSString isStringEmpty2:_getSubscribeDetail.preferentialReasons] == NO) {
//                    cell.subOneTF.text = _getSubscribeDetail.preferentialReasons;
//                }else {
//                    cell.subOneTF.placeholder = @"请输入优惠原因";
//                }
                
                UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(15, 50, 100, 20)];
                nameL.text = [_section2DataArr objectAtIndex:indexPath.row];
                nameL.font = [UIFont systemFontOfSize:15];
                [cell addSubview:nameL];
                cell.titleLabel.hidden = YES;
                cell.subOneTF.hidden = YES;
                UITextField *youhuiTextField = [[UITextField alloc] initWithFrame:CGRectMake(115, 45, EMM_WIDTH-130, 30)];
                youhuiTextField.delegate = self;
                youhuiTextField.returnKeyType =UIReturnKeyDone;
                youhuiTextField.textAlignment = NSTextAlignmentRight;
                youhuiTextField.font = [UIFont systemFontOfSize:15];
                [cell addSubview:youhuiTextField];
                [youhuiTextField addTarget:self action:@selector(youhuiTextFieldClick:) forControlEvents:UIControlEventEditingChanged];
                if ([NSString isStringEmpty2:_getSubscribeDetail.preferentialReasons] == NO) {
                    youhuiTextField.text = _getSubscribeDetail.preferentialReasons;
                }else {
                    youhuiTextField.placeholder = @"请输入优惠原因";
                }
            }
//            cell.subOneTF.tag = 3;
        }else if (indexPath.row == 4) {
            //折扣说明
            cell.subOneTF.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.discountNote] == NO) {
                cell.subOneTF.text = _getSubscribeDetail.discountNote;
            }else {
                cell.subOneTF.placeholder = @"请输入折扣说明";
            }
            cell.subOneTF.tag = 4;
            
        }
    }else if ([indexStr isEqualToString:@"3"]) {
        cell.titleLabel.text = [_section3DataArr objectAtIndex:indexPath.row];
        if (indexPath.row == 0) {
            //签约单价
    
            if ([NSString isStringEmpty2:_getSubscribeDetail.contractPrice] == NO) {
                cell.subtitleOneLable.text = [NSString stringWithFormat:@"%.2f元",[_getSubscribeDetail.contractPrice floatValue]];
            }else {
                cell.subtitleOneLable.text = @"元";
            }
        }else if (indexPath.row == 1) {
            //合同金额
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            if ([NSString isStringEmpty2:_getSubscribeDetail.contractAmount] == NO) {
                cell.subtitleOneLable.text = [NSString stringWithFormat:@"%.2f万元",[_getSubscribeDetail.contractAmount floatValue]];
            }else {
                cell.subtitleOneLable.text = @"元";
            }
        }else if (indexPath.row == 2) {
            //认筹转认购金
            if (_rowRCJH2 == 0) {
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = YES;
                cell.titleLabel.hidden = YES;
            }else {
                
                if ([NSString isStringEmpty2:_getSubscribeDetail.realAmount] == NO) {
                    cell.subtitleOneLable.text = [NSString stringWithFormat:@"%.2f元",[_getSubscribeDetail.realAmount floatValue]];
                }else {
                    cell.subtitleOneLable.text = @"元";
                }
            }
        }else if (indexPath.row == 3) {
            //应收定金
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.subTiltleTF.hidden = NO;
            cell.subTiltleTF.keyboardType = UIKeyboardTypeDecimalPad;
            cell.subtitleOneLable.text = @"元";
            if ([NSString isStringEmpty2:_getSubscribeDetail.depositReceivable] == NO) {
                cell.subTiltleTF.text= [NSString stringWithFormat:@"%.2f",[_getSubscribeDetail.depositReceivable floatValue]];
                
            }else {
                cell.subTiltleTF.placeholder = @"请输入认购金";
            }
            cell.subTiltleTF.tag = 3;
            [cell.subTiltleTF addTarget:self action:@selector(depositTextFieldClick:) forControlEvents:UIControlEventEditingChanged];
        }else if (indexPath.row == 4) {
            //付款方式
//            cell.biaoxinL.hidden = NO;
            cell.subTiltleTF.hidden = YES;
            cell.subTitleLabel.hidden = NO;
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.paymentMethod] == NO) {
                cell.subTitleLabel.text = _getSubscribeDetail.paymentMethod;
            }else {
                cell.subTitleLabel.text = @"请选择付款方式";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            }
            cell.seleBtn.hidden = NO;
            [cell.seleBtn addTarget:self action:@selector(paymentMethodBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }else if (indexPath.row == 5) {
            //成交类别
//            cell.biaoxinL.hidden = NO;
            cell.subTiltleTF.hidden = YES;
            cell.subTitleLabel.hidden = NO;
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_getSubscribeDetail.dealCategory] == NO) {
                cell.subTitleLabel.text = _getSubscribeDetail.dealCategory;
            }else {
                cell.subTitleLabel.text = @"请选择成交类别";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            }
            cell.seleBtn.hidden = NO;
            [cell.seleBtn addTarget:self action:@selector(dealCategoryBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }else if ([indexStr isEqualToString:@"4"]) {
        cell.titleLabel.text = [_section4DataArr objectAtIndex:indexPath.row];
     
        if (indexPath.row == 0) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-40, 10, 30, 30)];
            imageView.image = [UIImage imageNamed:@"rc_add"];
            [cell addSubview:imageView];
            cell.subTiltleTF.hidden = YES;
            cell.seleBtn.hidden = NO;
            [cell.seleBtn addTarget:self action:@selector(agentIdBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }else if (indexPath.row == 1) {
            for (int i = 0; i < _jingjirenArr.count; i++) {
                NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:i];
                NSString *jjr = [dict objectForKey:@"relationAgentName"];
                NSString *fybl = [dict objectForKey:@"proportionCommission"];
                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i*150, EMM_WIDTH, 150)];
                UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
                v1.backgroundColor = [UIColor colorFromHexCode:@"#FFF5E9"];
                [view addSubview:v1];
                UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 2, 30)];
                sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
                [view addSubview:sLabel6];
                
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(EMM_WIDTH-40, 10, 30, 30);
                [button setImage:[UIImage imageNamed:@"rc_dlet"] forState:UIControlStateNormal];
                button.tag = 100 + i;
                [button addTarget:self action:@selector(dletJJRButtonClick:) forControlEvents:UIControlEventTouchUpInside];
                [view addSubview:button];
                [cell addSubview:view];
                
                UILabel *titllName = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 100, 20)];
                titllName.font = [UIFont systemFontOfSize:15];
                titllName.text = [NSString stringWithFormat:@"经纪人%d", i+1];
                [view addSubview:titllName];
                
                UILabel *titllName1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 65, 100, 20)];
                titllName1.font = [UIFont systemFontOfSize:15];
                titllName1.text = @"经纪人";
                [view addSubview:titllName1];
                UIImageView *lineImage1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 99, EMM_WIDTH-20, 1)];
                lineImage1.backgroundColor = [UIColor colorFromHexCode:@"#e4e4e4"];
                [view addSubview:lineImage1];
                UILabel *titllName2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 115, 100, 20)];
                titllName2.font = [UIFont systemFontOfSize:15];
                titllName2.text = @"分佣比例";
                [view addSubview:titllName2];
                UIImageView *lineImage2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 149.5, EMM_WIDTH-20, 0.5)];
                lineImage2.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [view addSubview:lineImage2];
                
                UIImageView *im = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-10-12, 50+(50-16)/2, 12, 16)];
                im.image = [UIImage imageNamed:@"btn_qiaoj"];
                [view addSubview:im];
                
                UIButton *jjrbtn = [UIButton buttonWithType:UIButtonTypeSystem];
                jjrbtn.frame =CGRectMake(0, 65, EMM_WIDTH, 50);
                [jjrbtn addTarget:self action:@selector(jjrBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                jjrbtn.tag = 100 + i;
                [view addSubview:jjrbtn];
                //
                UILabel *labelJJR = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-227, 65, 200, 20)];
                labelJJR.font = [UIFont systemFontOfSize:15];
                labelJJR.textAlignment = NSTextAlignmentRight;
                [view addSubview:labelJJR];
                if ([NSString isStringEmpty2:jjr] == NO) {
                    labelJJR.text = jjr;
                    labelJJR.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                }else {
                    labelJJR.text = @"请选择";
                    labelJJR.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                }

                UILabel *lbfh = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH-25, 115, 15, 20)];
                lbfh.font = [UIFont systemFontOfSize:15];
                lbfh.text = @"%";
                [view addSubview:lbfh];
                
                UITextField *fyblTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-230, 110, 200, 30)];
                fyblTextField.font = [UIFont systemFontOfSize:15];
                fyblTextField.textAlignment = NSTextAlignmentRight;
                fyblTextField.keyboardType = UIKeyboardTypeDecimalPad;
                fyblTextField.delegate = self;
                if ([NSString isStringEmpty2:fybl] == NO && ![fybl isEqualToString:@""]) {
                    fyblTextField.text = fybl;
                }else {
                    fyblTextField.placeholder = @"请输入";
                }
                [fyblTextField addTarget:self action:@selector(fyblTextClick:) forControlEvents:UIControlEventEditingChanged];
                fyblTextField.tag = 100 + i;
                [view addSubview:fyblTextField];
            }
        }
    }else if ([indexStr isEqualToString:@"5"]) {
        cell.titleLabel.text = [_section5DataArr objectAtIndex:indexPath.row];
        if ([_dealCategoryId isEqualToString:@"1"]) {
            if (indexPath.row == 0) {
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
                cell.btn_qiaoJImageV.hidden = NO;
                UIButton *bu = [UIButton buttonWithType:UIButtonTypeSystem];
                bu.frame = CGRectMake(EMM_WIDTH-30, 10, 30, 30);
                [bu addTarget:self action:@selector(referenceNameBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                [cell addSubview:bu];
                cell.subTiltleTF.hidden = NO;
                if ([NSString isStringEmpty2:_getSubscribeDetail.referenceName] == YES) {
                    cell.subTiltleTF.placeholder = @"请输入";
                }else {
                    cell.subTiltleTF.text = _getSubscribeDetail.referenceName;
                }
                [cell.subTiltleTF addTarget:self action:@selector(remarkTextClick:) forControlEvents:UIControlEventEditingChanged];
                cell.subTiltleTF.tag = 1;
            }else if (indexPath.row == 1) {
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = NO;
                cell.btn_qiaoJImageV.hidden = NO;
                if ([NSString isStringEmpty2:_getSubscribeDetail.subscribeDate] == NO) {
                    cell.subTitleLabel.text = _getSubscribeDetail.subscribeDate;
                }else {
                    cell.subTitleLabel.text = @"未选择认购日期";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C7C7CD"];
                }
                cell.seleBtn.hidden = NO;
                [cell.seleBtn addTarget:self action:@selector(subscribeDateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            }else if (indexPath.row == 2) {
                //认购转合同到期日期
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = NO;
                cell.btn_qiaoJImageV.hidden = NO;
                if ([NSString isStringEmpty2:_getSubscribeDetail.dueTime] == NO) {
                    cell.subTitleLabel.text = _getSubscribeDetail.dueTime;
                }else {
                    cell.subTitleLabel.text = @"请选择合同到期日期";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                }
                cell.seleBtn.hidden = NO;
                [cell.seleBtn addTarget:self action:@selector(doeTimeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                
            }else if(indexPath.row == 3) {
                
#warning beizhu1
                //备注
                cell.subOneTF.hidden = YES;
                _remarkTV = [[UITextView alloc] initWithFrame:CGRectMake(60 + 30, 5, EMM_WIDTH-100, _remarkTVHeight + 6)];
                _remarkTV.delegate = self;
                _remarkTV.returnKeyType =UIReturnKeyDone;
                _remarkTV.textAlignment = NSTextAlignmentRight;
                [cell addSubview:_remarkTV];
                _remarkTV.font = [UIFont systemFontOfSize:15];
                if ([NSString isStringEmpty2:_getSubscribeDetail.remark] == NO) {
                    _remarkTV.text = _getSubscribeDetail.remark;
                    _remarkTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                }else {
                    _remarkTV.text = @"备注";
                    _remarkTV.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                }
                lineImage.hidden = YES;
                UIImageView *lineImage1 = [[UIImageView alloc] init];
                lineImage1.frame = CGRectMake(10, _remarkTVHeight + 16 - 0.5, EMM_WIDTH - 20, 0.5);
                lineImage1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [cell addSubview:lineImage1];
            }
        }else {
            if (indexPath.row == 0) {
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
                cell.btn_qiaoJImageV.hidden = NO;
                if ([NSString isStringEmpty2:_getSubscribeDetail.subscribeDate] == NO) {
                    cell.subTitleLabel.text = _getSubscribeDetail.subscribeDate;
                }else {
                    cell.subTitleLabel.text = @"未选择认购日期";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C7C7CD"];
                }
                cell.seleBtn.hidden = NO;
                [cell.seleBtn addTarget:self action:@selector(subscribeDateBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            }else if (indexPath.row == 1) {
                //认购转合同到期日期
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
                cell.subTiltleTF.hidden = YES;
                cell.subTitleLabel.hidden = NO;
                cell.btn_qiaoJImageV.hidden = NO;
                if ([NSString isStringEmpty2:_getSubscribeDetail.dueTime] == NO) {
                    cell.subTitleLabel.text = _getSubscribeDetail.dueTime;
                }else {
                    cell.subTitleLabel.text = @"请选择合同到期日期";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                }
                cell.seleBtn.hidden = NO;
                [cell.seleBtn addTarget:self action:@selector(doeTimeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                
            }else if(indexPath.row == 2) {
        
#warning beizhu1
                //备注
                cell.subOneTF.hidden = YES;
                _remarkTV = [[UITextView alloc] initWithFrame:CGRectMake(60 + 30, 5, EMM_WIDTH-100, _remarkTVHeight + 6)];
                _remarkTV.delegate = self;
                _remarkTV.returnKeyType =UIReturnKeyDone;
                _remarkTV.textAlignment = NSTextAlignmentRight;
                [cell addSubview:_remarkTV];
                _remarkTV.font = [UIFont systemFontOfSize:15];
                if ([NSString isStringEmpty2:_getSubscribeDetail.remark] == NO) {
                    _remarkTV.text = _getSubscribeDetail.remark;
                    _remarkTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                }else {
                    _remarkTV.text = @"备注";
                    _remarkTV.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                }
                lineImage.hidden = YES;
                UIImageView *lineImage1 = [[UIImageView alloc] init];
                lineImage1.frame = CGRectMake(10, _remarkTVHeight + 16 - 0.5, EMM_WIDTH - 20, 0.5);
                lineImage1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [cell addSubview:lineImage1];
            }
        }
    }else if ([indexStr isEqualToString:@"6"]) {
        if (indexPath.row == 0) {
            cell.titleLabel.hidden = YES;
            lineImage.hidden = YES;
            int columnCount=3;
            //没个格子的宽度和高度
            CGFloat appW=100;
            CGFloat appH=100;
            //计算间隙
            CGFloat appMargin=(EMM_WIDTH-columnCount*appW)/(columnCount+1);
            for (int i=0; i<_picArray.count; i++) {
                UIView *vi=[[UIView alloc] init];
                vi.backgroundColor=[UIColor whiteColor];
                
                //计算列号和行号
                int colX=i%columnCount;
                int rowY=i/columnCount;
                //计算坐标
                CGFloat appX=appMargin+colX*(appW+appMargin);
                CGFloat appY=rowY*(appH+appMargin);
                NSInteger gdH = 0;
                if (i <= 2) {
                    gdH = 10;
                }else {
                    gdH = 0;
                }
                vi.frame=CGRectMake(appX, appY+gdH, appW, appH);
                [cell addSubview:vi];
                
                UIImageView *im = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 90, 90)];
                [vi addSubview:im];
                NSMutableDictionary *dict = [_picArray objectAtIndex:i];
                NSString *type = [dict objectForKey:@"type"];
                
                if ([type isEqualToString:@"type"]) {
                    UIButton *buton = [UIButton buttonWithType:UIButtonTypeSystem];
                    buton.frame = CGRectMake(0, 0, 100, 100);
                    buton.backgroundColor = [UIColor whiteColor];
                    [buton addTarget:self action:@selector(butonClick:) forControlEvents:UIControlEventTouchUpInside];
                    [vi addSubview:buton];
                    
                    UIImageView *xuxianImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
                    xuxianImageV.image = [UIImage imageNamed:@"xuxian"];
                    [vi addSubview:xuxianImageV];
                    
                    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(40, 25, 20, 20)];
                    imageView.image = [UIImage imageNamed:@"btn_more"];
                    [vi addSubview:imageView];
                    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 55, 100, 20)];
                    label.text = @"添加附件";
                    label.textAlignment = NSTextAlignmentCenter;
                    label.font = [UIFont systemFontOfSize:15];
                    [vi addSubview:label];
                } else {
                    UIButton *seebuton = [UIButton buttonWithType:UIButtonTypeSystem];
                    seebuton.frame = CGRectMake(0, 0, 100, 100);
                    [seebuton addTarget:self action:@selector(seeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
                    seebuton.tag = i;
                    [vi addSubview:seebuton];
                    
                    UIImageView *xuxianImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
                    xuxianImageV.image = [UIImage imageNamed:@"xuxian"];
                    [vi addSubview:xuxianImageV];
                    
                    UIImageView *deleIm = [[UIImageView alloc] initWithFrame:CGRectMake(75, 5, 20, 20)];
                    deleIm.image = [UIImage imageNamed:@"rc_dlet"];
                    [vi addSubview:deleIm];
                    
                    UIButton *buton = [UIButton buttonWithType:UIButtonTypeSystem];
                    buton.frame = CGRectMake(70, 0, 30, 30);
                    [buton addTarget:self action:@selector(deleteButonClick:) forControlEvents:UIControlEventTouchUpInside];
                    buton.tag = i;
                    [vi addSubview:buton];
                    
                    if ([type isEqualToString:@"1"]) {
                        VGReturnGoodsPicDTO *temp = [[VGReturnGoodsPicDTO alloc] init];
                        temp.picImage = [dict objectForKey:@"image"];
                        im.image = temp.picImage;
                    }else if([type isEqualToString:@"2"]){
                        [im sd_setImageWithURL:[dict objectForKey:@"image"] placeholderImage:nil];
                    }
                }
            }
        }
    }
    return cell;
}

#pragma mark - 删除上传图片
- (void)deleteButonClick:(UIButton *)btn {
    NSMutableDictionary *dictPic = [_picArray objectAtIndex:btn.tag];
    NSString *type = [dictPic objectForKey:@"type"];
    if ([type isEqualToString:@"2"]) {
        NSString *url = [dictPic objectForKey:@"image"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        [dict setObject:url forKey:@"signedUrl"];
        NSString *str = @"1";
        [dict setObject:str forKey:@"headType"];
        [_imageList addObject:dict];
    }
    [_picArray removeObjectAtIndex:btn.tag];
    [_addSubscriptionTableView reloadData];
}

#pragma mark - 查看大图
- (void)seeButtonClick:(UIButton *)btn {
    if (_picArray.count > 0) {
        MHPhotoBrowserController *vc = [MHPhotoBrowserController new];
        NSMutableArray * bigImgArray = [NSMutableArray new];
        for (int i = 0; i < _picArray.count; i++) {
            NSMutableDictionary *dict = [_picArray objectAtIndex:i];
            NSString *type = [dict objectForKey:@"type"];
            if ([type isEqualToString:@"1"]) {
                [bigImgArray addObject:[MHPhotoModel photoWithImage:[dict objectForKey:@"image"]]];
            }else if([type isEqualToString:@"2"]){
                [bigImgArray addObject:[MHPhotoModel photoWithURL:[NSURL URLWithString:[dict objectForKey:@"image"]]]];
            }
        }
        vc.currentImgIndex = (int)btn.tag;
        vc.displayTopPage = YES;
        vc.displayDeleteBtn = YES;
        vc.imgArray = bigImgArray;
        //        vc.isShouDel = 1;
        vc.displayDeleteBtn = NO;
        [self presentViewController:vc animated:YES completion:nil];
    }else {
        [self showToast:@"暂无图片预览"];
    }
}

#pragma mark---- 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];
    
}

#pragma mark - 分区cell点击事件
- (void)doButton:(UIButton *)btn {
    NSString *string = [NSString stringWithFormat:@"%ld",btn.tag-100];
    //数组selectedArr里面存的数据和表头想对应，方便以后做比较
    if ([_selectedArr containsObject:string]) {
        if ([string isEqualToString:@"1"]) {
            [_selectedArr removeObject:string];
            [_selectedArr removeObject:@"2"];
            [_selectedArr removeObject:@"3"];
            [_selectedArr removeObject:@"4"];
            [_selectedArr removeObject:@"5"];

        }else {
            [_selectedArr removeObject:string];
        }
    }else {
        if ([string isEqualToString:@"1"]) {
            [_selectedArr addObject:string];
            [_selectedArr addObject:@"2"];
            [_selectedArr addObject:@"3"];
            [_selectedArr addObject:@"4"];
            [_selectedArr addObject:@"5"];

        }else {
            [_selectedArr addObject:string];
        }
    }
    [_addSubscriptionTableView reloadData];
}

#pragma mark - 第0分区 所有的调用方法
//textFile方法调用
- (void)superOneTilteTextFieldClick:(UITextField *)textField {
    if (textField.tag == 100) {//认购编号
        _getSubscribeDetail.subscribeCode = textField.text;
    }
}

//第一分区 btn按钮调用方法
- (void)roomFYBtnClick:(UIButton *)btn {
// 如果是从房源详情页面进入，则不可以选择
    if (self.HouseingDetailTo) return;

    if ([_isrcNew isEqualToString:@"1"]) {
        [self showToast:@"认筹转认购不能修改房源"];
        return;
    }
    
    HousingViewController *hvn = [[HousingViewController alloc] init];
    [self.navigationController pushViewController:hvn animated:YES];
    
    hvn.housingNewBlock = ^(NSMutableArray *roomArr,NSString *huoing) {
        _roomList = [roomArr objectAtIndex:0];
        _getSubscribeDetail.subscribeHouses = huoing;
        _getSubscribeDetail.roomId = _roomList.roomId;
        _getSubscribeDetail.calculateArea = _roomList.calculateArea;
        _getSubscribeDetail.discountPrice = _roomList.discountPrice;
        _getSubscribeDetail.discountTotalPrice = _roomList.discountTotalPrice;
        _getSubscribeDetail.discountRate = _roomList.discountRate;
        _getSubscribeDetail.floorType = _roomList.floorType;
        if ([NSString isStringEmpty2:_getSubscribeDetail.floorType] == NO) {
            ////方案类别	String(1)	方案类别（0 低价；1 折扣）
            if ([_getSubscribeDetail.floorType isEqualToString:@"0"]) {
//                _jlDijiaAmount = _getSubscribeDetail.discountRate;
                _rowHitgZH0 = 50;
                _rowHitgZH3 = 0;
//                _jlDiscountAmount = _getSubscribeDetail.discountRate;
                //合同金额
                _getSubscribeDetail.contractAmount = [NSString getVal:2 val:[_getSubscribeDetail.discountTotalPrice floatValue]];
                float dis3 = [_getSubscribeDetail.calculateArea floatValue];
                float price = [_getSubscribeDetail.contractAmount floatValue];
                _getSubscribeDetail.contractPrice = [NSString getVal:2 val:price/dis3];
                _getSubscribeDetail.discountAfterAmount = nil;
                _getSubscribeDetail.addDiscountRate = nil;
                _getSubscribeDetail.discountAmount = nil;
            }else {
                _getSubscribeDetail.discountAmount = [NSString getVal:2 val:[_getSubscribeDetail.discountAmount floatValue]];//折扣金额
                _rowHitgZH0 = 0;
                _rowHitgZH3 = 0;
//                _jlDiscountRate = _getSubscribeDetail.discountRate;
                _getSubscribeDetail.addDiscountRate = [NSString stringWithFormat:@"%.2f",[_roomList.discountRate floatValue]];//折扣比例
                float dis2 = [_getSubscribeDetail.discountTotalPrice floatValue];
                
                _getSubscribeDetail.discountAmount = [NSString getVal:2 val:(100.00 - [_getSubscribeDetail.addDiscountRate floatValue])/100.00*dis2];
                float dis1 = [_getSubscribeDetail.discountAmount floatValue];
                float dis3 = [_getSubscribeDetail.calculateArea floatValue];
                float d2 = (dis2-dis1);
                float d3 = (d2/dis3);
                
                _getSubscribeDetail.contractPrice = [NSString getVal:2 val:d3];
                _getSubscribeDetail.contractAmount = [NSString getVal:2 val:d2];
            }
        }else {
            
        }
        [_addSubscriptionTableView reloadData];
    };
}

#pragma mark - 第1分区所有方法调用
/**
 *  功能描述：
 *  1.修改姓名输入框
 *  创建时间：16/10/26
 *
 *  更新时间：2017/02/17 下午
 *  更新人： wangguiping
 */
- (void)section1TextFieldClick:(UITextField *)textField {
    if (textField.tag == 1) {
        //客户名字
        _getSubscribeDetail.customerName = textField.text;
    }else if (textField.tag == 3) {
        //证件号
        _getSubscribeDetail.documentNumber = textField.text;
    }else if (textField.tag == 6) {
        //邮编
        if (textField.text.length != 0) {
            if (textField.text.length >6) {
                [self showToast:@"邮编不超过六位"];
                _getSubscribeDetail.postcode = nil;
                [_addSubscriptionTableView reloadData];
            }else {
                _getSubscribeDetail.postcode = textField.text;
            }
        }
    }
}
#pragma mark - 邮寄地址和备注textview代理方法
- (void)textViewDidBeginEditing:(UITextView *)textView{
    if (textView == _mailPostTV) {//邮寄地址
        if ([textView.text isEqualToString:@"请输入邮寄地址"]) {
            textView.text = nil;
            _mailPostTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        }else{
            _mailPostTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        }
    }
    if (textView == _remarkTV) {//备注
        if ([textView.text isEqualToString:@"备注"]) {
            textView.text = nil;
            _remarkTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        }else{
            _remarkTV.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        }
    }
}

- (void)textViewDidChange:(UITextView *)textView{
    if (textView == _mailPostTV) {//邮寄地址
        _getSubscribeDetail.mailPost = textView.text;
        _mailPostTVHeight = [self heightForString:_mailPostTV andWidth:EMM_WIDTH - 100];
    }
    if (textView == _remarkTV) {//备注
        _getSubscribeDetail.remark = textView.text;
        _remarkTVHeight = [self heightForString:_remarkTV andWidth:EMM_WIDTH - 100];
    }
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    [_addSubscriptionTableView reloadData];
}
//计算textView的高度
- (float) heightForString:(UITextView *)textView andWidth:(float)width{
    CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
    return sizeToFit.height;
}
// - 新增客户信息
- (void)newKHCYBtnClick:(UIButton *)btn {
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
    [dict setObject:@"" forKey:@"memberName"];
    [dict setObject:@"" forKey:@"documentType"];
    [dict setObject:@"" forKey:@"documentNumber"];
    [_jtcyDataArr addObject:dict];
    [_addSubscriptionTableView reloadData];
}
// - 选择证件类型
- (void)documentTypeBtnClick:(UIButton *) btn {
//    NSArray *arr = [NSArray arrayWithObjects:@"身份证",@"护照",@"营业执照",
//                    @"户口薄",@"军官证", @"临时身份证",@"港澳台同胞来往通行证",
//                    @"边民出入境通行证", @"外国人永久居留证",@"警官证", @"士兵证",@"其他", nil];
    if (_zjlxList.count == 0) {
        [self showToast:@"暂无可选项"];
        return;
    }
    
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    for (int i = 0; i < _zjlxList.count; i++) {
        NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
        [arr addObject:[dict objectForKey:@"dictionaryName"]];
    }
    
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"证件号类型" titleNmae:@"请选择" numLits:nil items:arr];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
        NSLog(@"%@",indet);
        if ([NSString isStringEmpty2:indet] == NO) {
            _getSubscribeDetail.documentType = indet;
            for (int i = 0; i < _zjlxList.count; i++) {
                NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
                if ([_getSubscribeDetail.documentType isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                    _documentTypeId = [dict objectForKey:@"dictionaryId"];
                }
            }
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}

//- 认购删除家庭成员
- (void)dletjtcyBtnClick:(UIButton *)btn {
    [_jtcyDataArr removeObjectAtIndex:btn.tag - 100];
    [_addSubscriptionTableView reloadData];
}

//- 选择家庭成员证件类型
- (void)zjleiBtnClick:(UIButton *)btn {
//    NSArray *arr = [NSArray arrayWithObjects:@"身份证",@"护照",@"营业执照",
//                    @"户口薄",@"军官证", @"临时身份证",@"港澳台同胞来往通行证",
//                    @"边民出入境通行证", @"外国人永久居留证",@"警官证", @"士兵证",@"其他", nil];
    if (_zjlxList.count == 0) {
        [self showToast:@"暂无可选项"];
        return;
    }
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    for (int i = 0; i < _zjlxList.count; i++) {
        NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
        [arr addObject:[dict objectForKey:@"dictionaryName"]];
    }
    
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"证件号类型" titleNmae:@"请选择" numLits:nil items:arr];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *numberString) {
        NSLog(@"%@",indet);
        if ([NSString isStringEmpty2:indet] == NO) {
            NSString *documentId = nil;
            for (int i = 0; i < _zjlxList.count; i++) {
                NSMutableDictionary *dict = [_zjlxList objectAtIndex:i];
                if ([indet isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                    documentId = [dict objectForKey:@"dictionaryId"];
                }
            }
            NSMutableDictionary *dict = [_jtcyDataArr objectAtIndex:btn.tag - 100];
            [dict setObject:documentId forKey:@"documentType"];
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}

//输入客户姓名
- (void)khNameTextFieldClick:(UITextField *)textField {
    NSMutableDictionary *dict = [_jtcyDataArr objectAtIndex:textField.tag - 100];
    if ([NSString isStringEmpty2:textField.text] == NO) {
        [dict setObject:textField.text forKey:@"memberName"];
    }else {
        [dict setObject:@"" forKey:@"memberName"];
    }
}

//输入证件号码
- (void)zjhmTextFieldFieldClick:(UITextField *)textField {
    NSMutableDictionary *dict = [_jtcyDataArr objectAtIndex:textField.tag - 100];
    if ([NSString isStringEmpty2:textField.text] == NO) {
        [dict setObject:textField.text forKey:@"documentNumber"];
    }else {
        [dict setObject:@"" forKey:@"documentNumber"];
    }
}

- (void)sellAmountWithSubscription {
    //折后总价
    /*
     1、折后总价：手动输入
     2、折扣金额=折前总价-折后总价
     3、折后比例=折后总价/折前总价
     4、合同金额：①折后总价为空时，等于折前总价；②折后总价不为空，等于折后总价
     */
    if ([NSString isStringEmpty2:_getSubscribeDetail.discountAfterAmount] == NO) {
        if (_getSubscribeDetail.discountAfterAmount.length > 0) {
            float dis = [_getSubscribeDetail.discountTotalPrice floatValue];//折前总价
            float dis2 = [_getSubscribeDetail.discountAfterAmount floatValue];
            float zkJE = dis - dis2;
            float zkBL = dis2/dis;
            float qyDj = [_getSubscribeDetail.calculateArea floatValue];
            float djJE = dis2/qyDj;
            _getSubscribeDetail.contractPrice = [NSString getVal:2 val:djJE];
            _getSubscribeDetail.discountAmount = [NSString getVal:2 val:zkJE];
            _getSubscribeDetail.addDiscountRate = [NSString getVal:2 val:zkBL*100];
            _getSubscribeDetail.contractAmount = [NSString getVal:2 val:[_getSubscribeDetail.discountAfterAmount floatValue]];
        }
    }else {
        //            _getSubscribeDetail.discountAfterAmount = nil;
        _getSubscribeDetail.discountAmount = nil;
        _getSubscribeDetail.addDiscountRate = nil;
        if ([NSString isStringEmpty2:_getSubscribeDetail.discountTotalPrice] == NO) {
            float dis3 = [_getSubscribeDetail.calculateArea floatValue];
            _getSubscribeDetail.contractAmount = [NSString getVal:2 val:[_getSubscribeDetail.discountTotalPrice floatValue] ];//合同金额
            float price = [_getSubscribeDetail.contractAmount floatValue];
            _getSubscribeDetail.contractPrice = [NSString getVal:2 val:price/dis3];
        }else {
            _getSubscribeDetail.contractAmount = nil;//合同金额
            _getSubscribeDetail.contractPrice = nil;
        }
        
    }
}

#pragma mark - 第2分区所有方法调用
- (void)section2TextFieldClick:(UITextField *)textField {
    if (textField.tag == 0) {
        //折后总价
        _getSubscribeDetail.discountAfterAmount = textField.text;
        [self sellAmountWithSubscription];
    }else if (textField.tag == 1) {
        //折扣金额
        
        _getSubscribeDetail.discountAmount = textField.text;

        if ([NSString isStringEmpty2:_getSubscribeDetail.discountTotalPrice] == NO) {
            float dis1 = [_getSubscribeDetail.discountAmount floatValue];
            float dis2 = [_getSubscribeDetail.discountTotalPrice floatValue];
            if (dis1 < dis2) {
                if (dis1 != 0) {
                    float dis3 = [_getSubscribeDetail.calculateArea floatValue];
                    float d1 = (1 - (dis1/dis2))*100;
                    float d2 = (dis2-dis1);
                    float d3 = (d2/dis3);
                    float dis4 = [_getSubscribeDetail.discountRate floatValue];
                    if (d1 < dis4) {
                        _xianshibd.hidden = NO; 
                        _rowHitgZH3 = 80;
                        
                    }else {
                        _xianshibd.hidden = YES;
                        _rowHitgZH3 = 0;
                    }
                    if (d1 > 0) {
                        NSString *str = [NSString getMoney2:d1];
                        _getSubscribeDetail.addDiscountRate = str;
                    }else {
                        _getSubscribeDetail.addDiscountRate = @"0";
                    }
                    _getSubscribeDetail.contractPrice = [NSString getVal:2 val:d3];
                    _getSubscribeDetail.contractAmount = [NSString getVal:2 val:d2];
                }else {
                    _getSubscribeDetail.addDiscountRate = @"100.00";
                }
            }else {
                [self showToast:@"输入的比折前总价大"];
            }
        }else {
            _getSubscribeDetail.addDiscountRate = nil;
            _getSubscribeDetail.contractPrice = nil;
            _getSubscribeDetail.contractAmount = nil;
            _getSubscribeDetail.discountAmount = nil;
            [self showToast:@"请先选中认购房源"];
        }
    }else if (textField.tag == 4) {
        //折扣说明
        _getSubscribeDetail.discountNote = textField.text;
    }
//    [_addSubscriptionTableView reloadData];
}

- (void)youhuiTextFieldClick:(UITextField *)textF {
    //优惠原因
    _getSubscribeDetail.preferentialReasons = textF.text;
}


#pragma mark - 第3分区所有方法调用
- (void)depositTextFieldClick:(UITextField *)textField {
    if (textField.tag == 3) {
        _getSubscribeDetail.depositReceivable = textField.text;
    }
}

#pragma mark - 第4分区所有方法调用
- (void)paymentMethodBtnClick:(UIButton *)btn {
    NSArray *arr = [NSArray arrayWithObjects:
                    @"一次性付款",@"分期付款",@"商业按揭",
                    @"公积金按揭 ", @"组合贷款", nil];
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"请选择付款方式" numLits:nil items:arr];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *numberId) {
        if ([NSString isStringEmpty2:indet] == NO) {
            _getSubscribeDetail.paymentMethod = indet;
            _paymentMethodId = numberId;
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}
//  选择成交方式
- (void)dealCategoryBtnClick:(UIButton *)btn {
    //1、推荐成交；2、单独成交；3、共同成交
    NSArray *arr = [NSArray arrayWithObjects:
                    @"推荐成交",@"单独成交",@"共同成交", nil];
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"请选择成交类别" numLits:nil items:arr];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *numberId) {
        if ([NSString isStringEmpty2:indet] == NO) {
            [_jingjirenArr removeAllObjects];
            _getSubscribeDetail.dealCategory = indet;
            _dealCategoryId = numberId;
            if ([_dealCategoryId isEqualToString:@"1"]) {
                _section5DataArr = [[NSMutableArray alloc] initWithObjects:@"推荐人",@"认购日期",@"认购转合同到期日期",@"备注",nil];
                [_titleDict setObject:_section5DataArr forKey:@"5"];
            }else {
                _section5DataArr = [[NSMutableArray alloc] initWithObjects:@"认购日期",@"认购转合同到期日期", @"备注",nil];
                [_titleDict setObject:_section5DataArr forKey:@"5"];
            }
            if ([NSString isStringEmpty2:indet] == NO) {
                NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
                NSString *userName = [userdf objectForKey:@"userName"];
                NSString *userId = [userdf objectForKey:@"userNameId"];
                NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
                [dict setObject:userId forKey:@"relationAgentId"];
                [dict setObject:userName forKey:@"relationAgentName"];
                [dict setObject:@"100" forKey:@"proportionCommission"];
                [_jingjirenArr addObject:dict];
            }
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}
// - 添加共同成交经纪人
- (void)agentIdBtnClick:(UIButton *)btn {
    if ([_dealCategoryId isEqualToString:@"1"] || [_dealCategoryId isEqualToString:@"2"]) {
        if (_jingjirenArr.count >= 1) {
            if ([_dealCategoryId isEqualToString:@"1"]) {
                [self showToast:@"推荐成交最多只能添加一位经纪人"];
                return;
            }
            [self showToast:@"单独成交最多只能添加一位经纪人"];
            return;
        }
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
        NSString *userName = [userdf objectForKey:@"userName"];
        NSString *userId = [userdf objectForKey:@"userNameId"];
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        [dict setObject:userId forKey:@"relationAgentId"];
        [dict setObject:userName forKey:@"relationAgentName"];
        [dict setObject:@"100" forKey:@"proportionCommission"];
        [_jingjirenArr addObject:dict];

    }else if ([_dealCategoryId isEqualToString:@"3"]) {
        if (_jingjirenArr.count >= 3) {
            [self showToast:@"共同成交最多添加三个经纪人"];
            return;
        }
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        [dict setObject:@"" forKey:@"relationAgentId"];
        [dict setObject:@"" forKey:@"relationAgentName"];
        [dict setObject:@"" forKey:@"proportionCommission"];
        [_jingjirenArr addObject:dict];
        
        if (_jingjirenArr.count == 1) {
            NSMutableDictionary *dict1 = [_jingjirenArr objectAtIndex:0];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *userName = [userdf objectForKey:@"userName"];
            NSString *userId = [userdf objectForKey:@"userNameId"];
            [dict1 setObject:userId forKey:@"relationAgentId"];
            [dict1 setObject:userName forKey:@"relationAgentName"];
            [dict1 setObject:@"100" forKey:@"proportionCommission"];
        }

    }else {
        [self showToast:@"请先选择成交类别"];
    }
    [_addSubscriptionTableView reloadData];
}

// - 删除经纪人
- (void)dletJJRButtonClick:(UIButton *)btn {
    [_jingjirenArr removeObjectAtIndex:btn.tag - 100];
    [_addSubscriptionTableView reloadData];
}

// - 选择经纪人
- (void)jjrBtnClick:(UIButton *)btn {
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选经纪人" numLits:nil items:_zyDataArr];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *number) {
        if ([NSString isStringEmpty2:indet] == NO) {
            NSString *sId;
            NSString *sName;
            if (indet.length > 0) {
                for (int i = 0; i < _zyData.count; i++) {
                    ConsultantList *list = [_zyData objectAtIndex:i];
                    if ([indet isEqualToString:list.consultantUserName]) {
                        sId = list.consultantUserId;
                        sName = list.consultantUserName;
                    }
                }
            }
            if (_jingjirenArr.count > 0) {
                NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:btn.tag - 100];
                if ([NSString isStringEmpty2:sId] == NO) {
                    [dict setObject:sId forKey:@"relationAgentId"];
                    
                }else {
                    [dict setObject:@"" forKey:@"relationAgentId"];
                }
                
                if ([NSString isStringEmpty2:sName] == NO) {
                    [dict setObject:sName forKey:@"relationAgentName"];
                    
                }else {
                    [dict setObject:@"" forKey:@"relationAgentName"];
                }
            }
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}
// - 分佣比例
- (void)fyblTextClick:(UITextField *)textField {
    NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:textField.tag - 100];
    if ([NSString isStringEmpty2:textField.text] == NO) {
        [dict setObject:textField.text forKey:@"proportionCommission"];
    }else {
        [dict setObject:@"" forKey:@"proportionCommission"];
    }
}
#pragma mark - 第5分区所有方法调用
//推荐人选择
- (void)referenceNameBtnClick:(UIButton *)btn {
    if (_recommendCustomerNameList.count == 0) {
        [self showToast:@"暂无推荐人可选"];
        return;
    }
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选推荐人" numLits:nil items:_recommendCustomerNameList];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *number) {
        if ([NSString isStringEmpty2:indet] == NO) {
            if (indet.length > 0) {
                for (int i = 0; i < _recommendCustomerList.count; i++) {
                    RecommendCustomerList *list = [_recommendCustomerList objectAtIndex:i];
                    if ([indet isEqualToString:list.customerName]) {
                        _referenceNameId = list.customerId;
                        _getSubscribeDetail.referenceName = list.customerName;
                    }
                }
            }else {
                _referenceNameId = nil;
                _getSubscribeDetail.referenceName = nil;
            }
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}


// - 认购日期
- (void)subscribeDateBtnClick:(UIButton *)btn {
    TimerShowMenuView *menuView = [[TimerShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block TimerShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTimerBlock:^(NSString *indet) {
        if ([NSString isStringEmpty2:indet] == NO) {
            _getSubscribeDetail.subscribeDate = indet;
            _getSubscribeDetail.dueTime = nil;
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}

// - 备注
- (void)remarkTextClick:(UITextField *)textField {
    if (textField.tag == 1) {
        _getSubscribeDetail.referenceName = textField.text;
    }
}

// - 认购转合同到期日期
- (void)doeTimeBtnClick:(UIButton *)btn {
    if ([NSString isStringEmpty2:_getSubscribeDetail.subscribeDate] == YES) {
        [self showToast:@"请先选择认购日期"];
        return;
    }
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    NSMutableArray *arr1 = [[NSMutableArray alloc] init];
    for (int i = 0; i < 7; i++) {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
        NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
        [dateFormatter1 setDateFormat:@"yyyy-MM-dd"];
        
        NSDate *date1 = [dateFormatter1 dateFromString:_getSubscribeDetail.subscribeDate];
        NSDate *nextDay = [NSDate dateWithTimeInterval:(i+1)*24*60*60 sinceDate:date1];//后一天
        NSString *tmer = [dateFormatter stringFromDate:nextDay];
        NSString *tmer1 = [dateFormatter1 stringFromDate:nextDay];
        [arr addObject:tmer];
        [arr1 addObject:tmer1];
    }
    NSLog(@"%@",arr);
    NSLog(@"%@",arr1);
    ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"请选择日期" numLits:nil items:arr];
    menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:menuView];
    __block ShowMenuView *weakMenuView = menuView;
    __block AddSubscriptionViewController *blockSelf = self;
    [menuView setTouchBlock:^(NSString *indet, NSString *numberId) {
        if ([NSString isStringEmpty2:indet] == NO) {
            _getSubscribeDetail.dueTime = [arr1 objectAtIndex:[numberId intValue]-1];
        }
        [weakMenuView removeFromSuperview];
        [blockSelf.addSubscriptionTableView reloadData];
    }];
}

-(void)textFieldDidEndEditing:(UITextField *)textField {
    [_addSubscriptionTableView reloadData];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{
    NSLog(@"-----------> %ld", textField.keyboardType);
    
    if(textField.keyboardType != 8) return YES;
    
    
    if ([textField.text rangeOfString:@"."].location==NSNotFound) {
        
        _isHaveDian = NO;
        
    }
    
    if ([string length]>0)
        
    {
        
        unichar single=[string characterAtIndex:0];//当前输入的字符
        
        if ((single >='0' && single<='9') || single=='.')//数据格式正确
            
        {
            
            //首字母不能为0和小数点
            
            if([textField.text length]==0){
                
                if(single == '.'){
                    
                    //                    [self alertView:@"亲，第一个数字不能为小数点"];
                    
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    
                    return NO;
                    
                }
                
                if (single == '0') {
                    
                    //                    [self alertView:@"亲，第一个数字不能为0"];
                    
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    
                    return NO;
                    
                }
                
            }
            
            if (single=='.')
                
            {
                
                if(!_isHaveDian)//text中还没有小数点
                    
                {
                    
                    _isHaveDian=YES;
                    
                    return YES;
                    
                }else
                    
                {
                    
                    //                    [self alertView:@"亲，您已经输入过小数点了"];
                    
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    
                    return NO;
                    
                }
                
            }
            
            else
                
            {
                
                if (_isHaveDian)//存在小数点
                    
                {
                    
                    //判断小数点的位数
                    
                    NSRange ran=[textField.text rangeOfString:@"."];
                    
                    NSInteger tt = range.location-ran.location;
                    
                    if (tt <= 2){
                        
                        return YES;
                        
                    }else{
                        
                        //                        [self alertView:@"亲，您最多输入两位小数"];
                        
                        return NO;
                        
                    }
                    
                }
                
                else
                    
                {
                    
                    return YES;
                    
                }
                
            }
            
        }else{//输入的数据格式不正确
            
            //            [self alertView:@"亲，您输入的格式不正确"];
            
            [textField.text stringByReplacingCharactersInRange:range withString:@""];
            
            return NO;
            
        }
        
    }
    
    else
    {
        
        return YES;
        
    }
    
}

#pragma mark - 初始化
- (void)initWithShowUI {
    UIButton *bcBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    bcBtn.frame = CGRectMake(10, EMM_HEIGHT-65-SafeAreaTopHeight, EMM_WIDTH/2-20, 45);
    bcBtn.backgroundColor = [UIColor colorFromHexCode:@"#f97242"];
    [bcBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bcBtn setTitle:@"保存" forState:UIControlStateNormal];
    bcBtn.layer.masksToBounds = YES;
    bcBtn.layer.cornerRadius = 5;
    bcBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [bcBtn addTarget:self action:@selector(bcBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bcBtn];
    
    UIButton *tjBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    tjBtn.frame = CGRectMake(EMM_WIDTH/2+10, EMM_HEIGHT-65-SafeAreaTopHeight, EMM_WIDTH/2-20, 45);
    tjBtn.backgroundColor = [UIColor colorFromHexCode:@"#c4302c"];
    [tjBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tjBtn setTitle:@"提交" forState:UIControlStateNormal];
    tjBtn.layer.masksToBounds = YES;
    tjBtn.layer.cornerRadius = 5;
    tjBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [tjBtn addTarget:self action:@selector(tjBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:tjBtn];
    
    [self sellAmountWithSubscription];
}

#pragma mark - bcBtnClick 保存
- (void)bcBtnClick:(UIButton *)btn {
    
    //    if (_subscribeCode.length == 0) {//认购编号
    //        [self showToast:@"认购编号未填写"];
    //        return;
    //    }
    if (_getSubscribeDetail.roomId.length == 0) {
        [self showToast:@"认购房源未选择"];
        return ;
    }
    //    if (_memberName.length == 0) {
    //        [self showToast:@"客户姓名未填写"];
    //        return ;
    //    }
    if (_getSubscribeDetail.customerName.length == 0) {
        [self showToast:@"客户姓名未填写"];
        return ;
    }
    //
        if (_getSubscribeDetail.documentType.length == 0) {
            [self showToast:@"证件类型未选择"];
            return ;
        }
        if (_getSubscribeDetail.documentNumber.length == 0) {
            [self showToast:@"证件号未填写"];
            return ;
        }
        if (_getSubscribeDetail.mobile.length == 0) {
            [self showToast:@"手机号码未填写"];
            return ;
        }
    //    if (_mailPost.length == 0) {
    //        [self showToast:@"邮寄地址未填写"];
    //        return ;
    //    }
//    NSString *ybString = _getSubscribeDetail.postcode;
//    if (ybString.length != 0) {
//        if (ybString.length >6) {
//            [self showToast:@"邮编不超过六位"];
//            return;
//        }
//    }
//    if (_jingjirenArr.count > 0) {
//        for (int i = 0; i < _khxxDataArr.count; i++) {
//            NSMutableDictionary *dict = [_khxxDataArr objectAtIndex:i];
//            NSString *memberName = [dict objectForKey:@"memberName"];
//            NSString *documentType = [dict objectForKey:@"documentType"];
//            NSString *documentNumber = [dict objectForKey:@"documentNumber"];
//            if ([NSString isStringEmpty2:memberName] == YES) {
//                [self showToast:@"新增客户信息名字未填写"];
//                return;
//            }
//            if ([NSString isStringEmpty2:documentType] == YES) {
//                [self showToast:@"新增客户信息证件类未选择"];
//                return;
//            }
//            if ([NSString isStringEmpty2:documentNumber] == YES) {
//                [self showToast:@"新增客户信息证件号未填写"];
//                return;
//            }
//        }
//    }
    
    if (_getSubscribeDetail.depositReceivable.length == 0) {
        [self showToast:@"认购金未填写"];
        return ;
    }
    
    
//    if (_getSubscribeDetail.paymentMethod.length == 0) {
//        [self showToast:@"付款方式未选择"];
//        return ;
//    }
//    if (_getSubscribeDetail.dealCategory.length == 0) {
//        [self showToast:@"成交类别未选择"];
//        return ;
//    }
    
    if (_jingjirenArr.count == 0) {
        [self showToast:@"未添加经纪人"];
        return;
    }
    
    
    if (_jingjirenArr.count == 1) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:0];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        if ([proportionCommission floatValue] != 100) {
            [self showToast:@"分佣比例不等于100%，请重新填写！"];
            return ;
        }
    }else if (_jingjirenArr.count == 2) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:0];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        NSMutableDictionary *dict1 = [_jingjirenArr objectAtIndex:1];
        NSString *relationAgentName1 = [dict1 objectForKey:@"relationAgentName"];
        if (relationAgentName1.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission1 = [dict1 objectForKey:@"proportionCommission"];
        if (proportionCommission1.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        if ([relationAgentName isEqualToString:relationAgentName1]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        
        if (([proportionCommission floatValue] + [proportionCommission1 floatValue]) != 100) {
            [self showToast:@"分佣比例不等于100%，请重新填写！"];
            return;
        }
        
    }else if (_jingjirenArr.count == 3) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:0];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        NSMutableDictionary *dict1 = [_jingjirenArr objectAtIndex:1];
        NSString *relationAgentName1 = [dict1 objectForKey:@"relationAgentName"];
        if (relationAgentName1.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission1 = [dict1 objectForKey:@"proportionCommission"];
        if (proportionCommission1.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        NSMutableDictionary *dict2 = [_jingjirenArr objectAtIndex:2];
        NSString *relationAgentName2 = [dict2 objectForKey:@"relationAgentName"];
        if (relationAgentName2.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission2 = [dict2 objectForKey:@"proportionCommission"];
        if (proportionCommission2.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        if ([relationAgentName isEqualToString:relationAgentName1]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        if ([relationAgentName isEqualToString:relationAgentName2]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        if ([relationAgentName1 isEqualToString:relationAgentName2]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        if (([proportionCommission floatValue] + [proportionCommission1 floatValue] + [proportionCommission2 floatValue]) != 100) {
            [self showToast:@"分佣比例不等于100%，请重新填写！"];
            return;
        }
        
    }
    
    if ([_getSubscribeDetail.dealCategory isEqualToString:@"推荐成交"]) {
        if (_getSubscribeDetail.referenceName.length == 0) {
            [self showToast:@"推荐人不能为空"];
            return;
        }
    }
  
    if ([_getSubscribeDetail.floorType isEqualToString:@"0"]) {
        
    }else {
        if ([_getSubscribeDetail.discountApproval isEqualToString:@"0"]) {
        }else {
            if ([NSString isStringEmpty2:_getSubscribeDetail.preferentialReasons] == YES) {
                [self showToast:@"优惠原因未填写"];
                return;
            }
        }
    }
    for (int i = 0; i < _jingjirenArr.count; i++) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:i];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
    }
    for (int i = 0; i < _jingjirenArr.count; i++) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:i];
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未输入"];
            return;
        }
    }
    
    if (_getSubscribeDetail.subscribeDate.length == 0) {
        [self showToast:@"认购日期未选择"];
        return ;
    }
    
    if (_getSubscribeDetail.dueTime.length == 0) {
        [self showToast:@"认购转合同到期日期未选择"];
        return ;
    }
    
    [self showHudInWindow:@"正在请求稍等......"];
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    
    if (_imageList.count > 0) {
        for (int j = 0; j < _imageList.count; j++) {
            NSMutableDictionary *dictImage = [_imageList objectAtIndex:j];
            NSString *headType = [dictImage objectForKey:@"headType"];
            if ([headType isEqualToString:@"1"] ) {
                [arr addObject:dictImage];
            }
        }
    }
    
    [_imageList removeAllObjects];

    for (int j = 0; j < arr.count; j++) {
        NSMutableDictionary *dictImage = [arr objectAtIndex:j];
        [_imageList addObject:dictImage];
    }
    
    
    for (int i=0; i<_picArray.count; i++) {
        NSMutableDictionary *dictPic = [_picArray objectAtIndex:i];
        NSString *type = [dictPic objectForKey:@"type"];
        if ([type isEqualToString:@"1"]) {
           
            NSData* imageData = UIImageJPEGRepresentation([dictPic objectForKey:@"image"], 0.1);
            NSString *base64EncodedString = [NSString base64StringFromData:imageData length:[imageData length]];
            NSString *encodedImageStr = base64EncodedString;
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            [dict setObject:encodedImageStr forKey:@"signedUrl"];
            [dict setObject:@".png" forKey:@"headType"];
            [_imageList addObject:dict];
        }else if ([type isEqualToString:@"2"]){
            NSString *url = [dictPic objectForKey:@"image"];
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            [dict setObject:url forKey:@"signedUrl"];
            NSString *str = @"0";
            [dict setObject:str forKey:@"headType"];
            [_imageList addObject:dict];
        }
    }
    
    if ([_isSFNew isEqualToString:@"0"]) {
        [self postAddAuditStatus:@"0"];
    }else {//修改
        [self postEAuditStatus:@"0"];
    }
}

#pragma mark - tjBtnClick 提交
/**
 *  功能描述：
 *  1.修改判断姓名为必填
 *  创建时间：16/10/26
 *
 *  更新时间：2017/02/17 下午
 *  更新人： wangguiping
 */
- (void)tjBtnClick:(UIButton *)btn {
    //    if (_subscribeCode.length == 0) {//认购编号
    //        [self showToast:@"认购编号未填写"];
    //        return;
    //    }
    if (_getSubscribeDetail.roomId.length == 0) {
        [self showToast:@"认购房源未选择"];
        return ;
    }
    if (_getSubscribeDetail.customerName.length == 0) {
        [self showToast:@"客户姓名未填写"];
        return ;
    }
    if (_getSubscribeDetail.customerName.length == 0) {
        [self showToast:@"客户姓名未填写"];
        return ;
    }
    //
    if (_getSubscribeDetail.documentType.length == 0) {
        [self showToast:@"证件类型未选择"];
        return ;
    }
    if (_getSubscribeDetail.documentNumber.length == 0) {
        [self showToast:@"证件号未填写"];
        return ;
    }
    if (_getSubscribeDetail.mobile.length == 0) {
        [self showToast:@"手机号码未填写"];
        return ;
    }
    //
    //    if (_documentName.length == 0) {
    //        [self showToast:@"证件类型未选择"];
    //        return ;
    //    }
    //    if (_documentNumber.length == 0) {
    //        [self showToast:@"证件号未填写"];
    //        return ;
    //    }
    //    if (_mobile.length == 0) {
    //        [self showToast:@"手机号码未填写"];
    //        return ;
    //    }
    //    if (_mailPost.length == 0) {
    //        [self showToast:@"邮寄地址未填写"];
    //        return ;
    //    }
    
//    NSString *ybString = _getSubscribeDetail.postcode;
//    if (ybString.length != 0) {
//        if (ybString.length >6) {
//            [self showToast:@"邮编不超过六位"];
//            return;
//        }
//    }
    
    //    if (_jingjirenArr.count > 0) {
    //        for (int i = 0; i < _khxxDataArr.count; i++) {
    //            NSMutableDictionary *dict = [_khxxDataArr objectAtIndex:i];
    //            NSString *memberName = [dict objectForKey:@"memberName"];
    //            NSString *documentType = [dict objectForKey:@"documentType"];
    //            NSString *documentNumber = [dict objectForKey:@"documentNumber"];
    //            if ([NSString isStringEmpty2:memberName] == YES) {
    //                [self showToast:@"新增客户信息名字未填写"];
    //                return;
    //            }
    //            if ([NSString isStringEmpty2:documentType] == YES) {
    //                [self showToast:@"新增客户信息证件类未选择"];
    //                return;
    //            }
    //            if ([NSString isStringEmpty2:documentNumber] == YES) {
    //                [self showToast:@"新增客户信息证件号未填写"];
    //                return;
    //            }
    //        }
    //    }
    
    if (_getSubscribeDetail.depositReceivable.length == 0) {
        [self showToast:@"认购金未填写"];
        return ;
    }
    
    
//    if (_getSubscribeDetail.paymentMethod.length == 0) {
//        [self showToast:@"付款方式未选择"];
//        return ;
//    }
//    if (_getSubscribeDetail.dealCategory.length == 0) {
//        [self showToast:@"成交类别未选择"];
//        return ;
//    }
    
    if (_jingjirenArr.count == 0) {
        [self showToast:@"未添加经纪人"];
        return;
    }
    
    
    if (_jingjirenArr.count == 1) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:0];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
    
        if ([proportionCommission floatValue] != 100) {
            [self showToast:@"分佣比例不等于100%，请重新填写！"];
            return ;
        }
        
    }else if (_jingjirenArr.count == 2) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:0];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        NSMutableDictionary *dict1 = [_jingjirenArr objectAtIndex:1];
        NSString *relationAgentName1 = [dict1 objectForKey:@"relationAgentName"];
        if (relationAgentName1.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission1 = [dict1 objectForKey:@"proportionCommission"];
        if (proportionCommission1.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        if ([relationAgentName isEqualToString:relationAgentName1]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        
        if (([proportionCommission floatValue] + [proportionCommission1 floatValue]) != 100) {
            [self showToast:@"分佣比例不等于100%，请重新填写！"];
            return;
        }
       
    }else if (_jingjirenArr.count == 3) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:0];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        NSMutableDictionary *dict1 = [_jingjirenArr objectAtIndex:1];
        NSString *relationAgentName1 = [dict1 objectForKey:@"relationAgentName"];
        if (relationAgentName1.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission1 = [dict1 objectForKey:@"proportionCommission"];
        if (proportionCommission1.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        
        NSMutableDictionary *dict2 = [_jingjirenArr objectAtIndex:2];
        NSString *relationAgentName2 = [dict2 objectForKey:@"relationAgentName"];
        if (relationAgentName2.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
        NSString *proportionCommission2 = [dict2 objectForKey:@"proportionCommission"];
        if (proportionCommission2.length == 0) {
            [self showToast:@"分佣比例未填写"];
            return;
        }
        if ([relationAgentName isEqualToString:relationAgentName1]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        if ([relationAgentName isEqualToString:relationAgentName2]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
        if ([relationAgentName1 isEqualToString:relationAgentName2]) {
            [self showToast:@"不能选择相同的经纪人"];
            return;
        }
       
        if (([proportionCommission floatValue] + [proportionCommission1 floatValue] + [proportionCommission2 floatValue]) != 100) {
            [self showToast:@"分佣比例不等于100%，请重新填写！"];
            return;
        }
       
    }
    
    if ([_getSubscribeDetail.dealCategory isEqualToString:@"推荐成交"]) {
        if (_getSubscribeDetail.referenceName.length == 0) {
            [self showToast:@"推荐人不能为空"];
            return;
        }
       
    }
    
  
    if ([_getSubscribeDetail.floorType isEqualToString:@"0"]) {
        
    }else {
        if ([_getSubscribeDetail.discountApproval isEqualToString:@"0"]) {
        }else {
            if ([NSString isStringEmpty2:_getSubscribeDetail.preferentialReasons] == YES) {
                [self showToast:@"优惠原因未填写"];
                return;
            }
        }
    }
    
    for (int i = 0; i < _jingjirenArr.count; i++) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:i];
        NSString *relationAgentName = [dict objectForKey:@"relationAgentName"];
        if (relationAgentName.length == 0) {
            [self showToast:@"未选择经纪人"];
            return;
        }
    }
    
    for (int i = 0; i < _jingjirenArr.count; i++) {
        NSMutableDictionary *dict = [_jingjirenArr objectAtIndex:i];
        NSString *proportionCommission = [dict objectForKey:@"proportionCommission"];
        if (proportionCommission.length == 0) {
            [self showToast:@"分佣比例未输入"];
            return;
        }
    }
    
    if (_getSubscribeDetail.subscribeDate.length == 0) {
        [self showToast:@"认购日期未选择"];
        return ;
    }
    
    if (_getSubscribeDetail.dueTime.length == 0) {
        [self showToast:@"认购转合同到期日期未选择"];
        return ;
    }

    [self showHudInWindow:@"正在请求稍等......"];
    
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    
    if (_imageList.count > 0) {
        for (int j = 0; j < _imageList.count; j++) {
            NSMutableDictionary *dictImage = [_imageList objectAtIndex:j];
            NSString *headType = [dictImage objectForKey:@"headType"];
            if ([headType isEqualToString:@"1"] ) {
                [arr addObject:dictImage];
            }
        }
    }
    
    [_imageList removeAllObjects];
    
    for (int j = 0; j < arr.count; j++) {
        NSMutableDictionary *dictImage = [arr objectAtIndex:j];
        [_imageList addObject:dictImage];
    }
    for (int i=0; i<_picArray.count; i++) {
        NSMutableDictionary *dictPic = [_picArray objectAtIndex:i];
        NSString *type = [dictPic objectForKey:@"type"];
        if ([type isEqualToString:@"1"]) {
            NSData* imageData = UIImageJPEGRepresentation([dictPic objectForKey:@"image"], 0.1);
            NSString *base64EncodedString = [NSString base64StringFromData:imageData length:[imageData length]];
            NSString *encodedImageStr = base64EncodedString;
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            [dict setObject:encodedImageStr forKey:@"signedUrl"];
            [dict setObject:@".png" forKey:@"headType"];
            [_imageList addObject:dict];
        }else if ([type isEqualToString:@"2"]){
            NSString *url = [dictPic objectForKey:@"image"];
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            [dict setObject:url forKey:@"signedUrl"];
            NSString *str = @"0";
            [dict setObject:str forKey:@"headType"];
            [_imageList addObject:dict];
        }
    }
    
    if ([_isSFNew isEqualToString:@"0"]) {
        [self postAddAuditStatus:@"1"];
    }else {//修改
        [self postEAuditStatus:@"1"];
    }
}

#pragma mark - 新增Api
- (void)postAddAuditStatus:(NSString *)auditStatus {
    
    AddSubscribeApi *api = [[AddSubscribeApi alloc] initWithSubscribeCode:_getSubscribeDetail.subscribeCode
                                                               customerId:self.customerId
                                                             payDepositId:_getSubscribeDetail.payDepositId
                                                           payDepositCode:_getSubscribeDetail.payDepositCode
                                                          payDepositMoney:_getSubscribeDetail.payDepositMoney
                                                                   roomId:_getSubscribeDetail.roomId
                                                            calculateArea:_getSubscribeDetail.calculateArea
                                                            discountPrice:_getSubscribeDetail.discountPrice
                                                       discountTotalPrice:_getSubscribeDetail.discountTotalPrice
                                                           discountAmount:_getSubscribeDetail.discountAmount
                                                             discountRate:_getSubscribeDetail.addDiscountRate
                                                      preferentialReasons:_getSubscribeDetail.preferentialReasons
                                                             discountNote:_getSubscribeDetail.discountNote
                                                         discountApproval:_getSubscribeDetail.discountApproval
                                                            contractPrice:_getSubscribeDetail.contractPrice
                                                           contractAmount:_getSubscribeDetail.contractAmount
                                                        depositReceivable:_getSubscribeDetail.depositReceivable
                                                                  dueTime:_getSubscribeDetail.dueTime
                                                            paymentMethod:_paymentMethodId
                                                                floorType:_getSubscribeDetail.floorType
                                                      discountAfterAmount:_getSubscribeDetail.discountAfterAmount
                                                             dealCategory:_dealCategoryId
                                                         dealCategoryList:_jingjirenArr
                                                            subscribeDate:_getSubscribeDetail.subscribeDate
                                                                   remark:_getSubscribeDetail.remark
                                                              auditStatus:auditStatus
                                                               memberName:_getSubscribeDetail.customerName
                                                             documentType:_documentTypeId
                                                           documentNumber:_getSubscribeDetail.documentNumber
                                                                   mobile:_getSubscribeDetail.mobile
                                                                 mailPost:_getSubscribeDetail.mailPost
                                                                 postcode:_getSubscribeDetail.postcode
                                                       customerFamilyList:_jtcyDataArr
                                                              referenceId:_referenceNameId
                                                            referenceName:_getSubscribeDetail.referenceName
                                                      referenceProportion:@"0"
                                                                imageList:_imageList];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        AddSubscribeApi *result = (AddSubscribeApi *)request;
        if (result.isSuccess) {
            [self hideHud];
            if ([_isTransaction isEqualToString:@"1"]) {
                for (UIViewController *controller in self.navigationController.viewControllers) {
                    if ([controller isKindOfClass:[SubscriptionViewController class]]) {
                        SubscriptionViewController *svc =(SubscriptionViewController *)controller;
                        [self.navigationController popToViewController:svc animated:YES];
                    }
                }
            }else {
                if ([result.resultData.result isEqualToString:@"1"]) {
                    if ([NSString isStringEmpty2:result.resultData.errorMsg] == NO) {
                        [self showToast:result.resultData.errorMsg];
                    }else {
                        
                        [self showToast:@"操作成功。。"];
                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                            if(self.HouseingDetailTo) {
                                [self.navigationController popToRootViewControllerAnimated:YES];
                            }else {
                                [self.navigationController popViewControllerAnimated:YES];
                            }
                        });
                    }
                }else {
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }
        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
    
}

#pragma mark - 修改Api
-(void)postEAuditStatus:(NSString *)auditStatus {
    
    EditSubscribeApi *api = [[EditSubscribeApi alloc] initWithPayDepositId:_getSubscribeDetail.payDepositId
                                                            payDepositCode:_getSubscribeDetail.payDepositCode
                                                           payDepositMoney:_getSubscribeDetail.payDepositMoney
                                                               subscribeId:_subscribeId
                                                                    roomId:_getSubscribeDetail.roomId
                                                             calculateArea:_getSubscribeDetail.calculateArea
                                                             discountPrice:_getSubscribeDetail.discountPrice
                                                        discountTotalPrice:_getSubscribeDetail.discountTotalPrice
                                                            discountAmount:_getSubscribeDetail.discountAmount
                                                              discountRate:_getSubscribeDetail.addDiscountRate
                                                       preferentialReasons:_getSubscribeDetail.preferentialReasons
                                                          discountApproval:_getSubscribeDetail.discountApproval
                                                              discountNote:_getSubscribeDetail.discountNote
                                                             contractPrice:_getSubscribeDetail.contractPrice
                                                            contractAmount:_getSubscribeDetail.contractAmount
                                                         depositReceivable:_getSubscribeDetail.depositReceivable
                                                                   dueTime:_getSubscribeDetail.dueTime
                                                             paymentMethod:_paymentMethodId
                                                              dealCategory:_dealCategoryId
                                                                 floorType:_getSubscribeDetail.floorType
                                                       discountAfterAmount:_getSubscribeDetail.discountAfterAmount
                                                          dealCategoryList:_jingjirenArr
                                                             subscribeDate:_getSubscribeDetail.subscribeDate
                                                                    remark:_getSubscribeDetail.remark
                                                               auditStatus:auditStatus
                                                                memberName:_getSubscribeDetail.customerName
                                                              documentType:_documentTypeId
                                                            documentNumber:_getSubscribeDetail.documentNumber
                                                                    mobile:_getSubscribeDetail.mobile
                                                                  mailPost:_getSubscribeDetail.mailPost
                                                                  postcode:_getSubscribeDetail.postcode
                                                        customerFamilyList:_jtcyDataArr
                                                               referenceId:_referenceNameId
                                                             referenceName:_getSubscribeDetail.referenceName
                                                       referenceProportion:@"0"
                                                                 imageList:_imageList];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        EditSubscribeApi *result = (EditSubscribeApi *)request;
        if (result.isSuccess) {
            [self hideHud];
            if ([_isTransaction isEqualToString:@"1"]) {
                for (UIViewController *controller in self.navigationController.viewControllers) {
                    if ([controller isKindOfClass:[SubscriptionViewController class]]) {
                        [self creatNSNotificationCenter];
                        SubscriptionViewController *svc =(SubscriptionViewController *)controller;
                        [self.navigationController popToViewController:svc animated:YES];
                    }
                }
            }else {
                if ([result.resultData.result isEqualToString:@"1"]) {
                    if ([NSString isStringEmpty2:result.resultData.errorMsg] == NO) {
                        [self showToast:result.resultData.errorMsg];
                    }else {
                        if (_subscriptionUpViewBlock) {
                            _subscriptionUpViewBlock();
                        }
                        [self.navigationController popViewControllerAnimated:YES];
                    }
                }else {
                    if (_subscriptionUpViewBlock) {
                        _subscriptionUpViewBlock();
                    }
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }

        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 选择图片
- (void)butonClick:(UIButton *)btn {
    UIActionSheet *choiceSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"取消"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"拍照", @"从相册中选取", nil];
    [choiceSheet showInView:self.view];
    
}


#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        // 拍照
        [self showPhotosFromCamera];
        
    } else if (buttonIndex == 1) {
        // 从相册中选取
        [self showSelectPhotos];
        
    }
}


////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark - 调用系统相机和相册
////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma mark camera utility

////////////////////////////////////////////////////////////////////////////////////////////////////

- (BOOL) isCameraAvailable
{
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isRearCameraAvailable
{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

- (BOOL) isFrontCameraAvailable
{
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}

- (BOOL) doesCameraSupportTakingPhotos
{
    return [self cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}

- (BOOL) isPhotoLibraryAvailable
{
    return [UIImagePickerController isSourceTypeAvailable:
            UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickVideosFromPhotoLibrary
{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (BOOL) canUserPickPhotosFromPhotoLibrary
{
    return [self
            cameraSupportsMedia:(__bridge NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}


- (BOOL) cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType
{
    __block BOOL result = NO;
    if ([paramMediaType length] == 0) {
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType]){
            result = YES;
            *stop= YES;
        }
    }];
    return result;
}
#pragma mark 1 拍照
- (void)showPhotosFromCamera
{
    
    // 拍照
    if ([self isCameraAvailable] && [self doesCameraSupportTakingPhotos]) {
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        controller.sourceType = UIImagePickerControllerSourceTypeCamera;
        if ([self isFrontCameraAvailable]) {
            controller.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        }
        
        NSMutableArray *mediaTypes = [[NSMutableArray alloc] init];
        [mediaTypes addObject:(__bridge NSString *)kUTTypeImage];
        controller.mediaTypes = mediaTypes;
        controller.delegate = self;
        [self presentViewController:controller
                           animated:YES
                         completion:^(void){
                             NSLog(@"Picker View Controller is presented");
                         }];
    } else {
        [self alertWithTitle:@"无法访问相机" msg:@"在\"设置>隐私>相机>Vgo\"中点击启用."];
    }
}

#pragma mark - UIImagePickerControllerDelegate
#pragma mark 2 拍照
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self showThisImagePicker:picker info:info];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:^(){
    }];
}


#pragma mark 3 拍照
- (void)showThisImagePicker:(UIImagePickerController *)picker info:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:^() {
        UIImage *portraitImg = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        NSData* imageData = UIImageJPEGRepresentation(portraitImg, 0.1);
        
        if (imageData == NULL) {
            return;
        }
        
        for (int i = 0; i < _picArray.count; i++) {
            NSMutableDictionary *jiaDict = [_picArray objectAtIndex:i];
            NSString *type = [jiaDict objectForKey:@"type"];
            if ([type isEqualToString:@"type"]) {
                [_picArray removeObjectAtIndex:i];
            }
        }
        
        NSMutableDictionary *dictIm = [[NSMutableDictionary alloc] init];
        [dictIm setObject:portraitImg forKey:@"image"];
        [dictIm setObject:@"1" forKey:@"type"];
        [_picArray addObject:dictIm];
        
        NSMutableDictionary *jDict = [[NSMutableDictionary alloc] init];
        [jDict setObject:@"image" forKey:@"image"];
        [jDict setObject:@"type" forKey:@"type"];
        [_picArray addObject:jDict];
        [_addSubscriptionTableView reloadData];
    }];
}

#pragma mark 照片
- (void)showSelectPhotos
{
    if (![self isPhotoLibraryAvailable]) {
        [self alertWithTitle:@"无法访问相机" msg:@"在\"设置>隐私>照片>Vgo\"中点击启用."];
        return;
    }
    QBImagePickerController *imagePickerController = [QBImagePickerController new];
    imagePickerController.delegate = self;
    imagePickerController.allowsMultipleSelection = YES;
    imagePickerController.showsNumberOfSelectedAssets = YES;
    //    imagePickerController.maximumNumberOfSelection = 5;
    
    [self presentViewController:imagePickerController animated:YES completion:NULL];
}


#pragma mark - QBImagePickerControllerDelegate

- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets
{
    NSLog(@"Selected assets:");
    NSLog(@"%@", assets);// addbtn100
    for (ALAsset *result in assets) {
        // ALAsset的类型
        NSString *assetType = [result valueForProperty:ALAssetPropertyType];
        if ([assetType isEqualToString:ALAssetTypePhoto]){
            ALAssetRepresentation *assetRepresentation =[result defaultRepresentation];
            //            CGFloat imageScale = [assetRepresentation scale];
            UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation];
            
            CGImageRef imageReference = [assetRepresentation fullResolutionImage];
            // 对找到的图片进行操作
            UIImage *image = [[UIImage alloc] initWithCGImage:imageReference scale:1.0 orientation:imageOrientation];
            if (image != nil){
                for (int i = 0; i < _picArray.count; i++) {
                    NSMutableDictionary *jiaDict = [_picArray objectAtIndex:i];
                    NSString *type = [jiaDict objectForKey:@"type"];
                    if ([type isEqualToString:@"type"]) {
                        [_picArray removeObjectAtIndex:i];
                    }
                }
                
               
                NSMutableDictionary *dictIm = [[NSMutableDictionary alloc] init];
                [dictIm setObject:image forKey:@"image"];
                [dictIm setObject:@"1" forKey:@"type"];
                [_picArray addObject:dictIm];
                
                NSMutableDictionary *jDict = [[NSMutableDictionary alloc] init];
                [jDict setObject:@"image" forKey:@"image"];
                [jDict setObject:@"type" forKey:@"type"];
                [_picArray addObject:jDict];
                
                [_addSubscriptionTableView reloadData];
            } else {
                NSLog(@"Failed to create the image.");
            }
        }
    }
    
    [self dismissViewControllerAnimated:YES completion:NULL];
    
}

- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

- (NSString *)postImage:(UIImage *)portraitImg
{
    //    portraitImg = [portraitImg imageByScalingAndCroppingForSize:CGSizeMake(60, 60)];
    
    NSData* imageData = UIImageJPEGRepresentation(portraitImg, 0.1);
    
    if (imageData == NULL) {
        return nil;
    }
    
    NSString *base64EncodedString = [NSString base64StringFromData:imageData length:[imageData length]];
    
    NSString *encodedImageStr = base64EncodedString;
    
    return encodedImageStr;
}

@end
